2013-04-08 75 views
0

我试图读取上传的文件使用FileUpload控件的服务器,但是,我流汗以下错误:FileUpload控件读

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/> , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user

我调查它似乎该文件夹没有网络服务帐户的权限,所以我添加它,但问题仍然存在。这里是我的FileUpload控件的代码:

<asp:FileUpload ID="FileUpload1" runat="server" style="top: 164px; left: 12px;  position: absolute; height: 22px; width: 281px" /> 

这里是我使用保存在我的服务器上的文件的代码:

protected void Button1_Click1(object sender, EventArgs e) 
{ 
    FileUpload1.SaveAs("C:\\folder\\autoTrack.xlsx"); 
    StatusLabel.Text = FileUpload1.PostedFile.FileName; 
    if (FileUpload1.PostedFile.FileName != "") 
    { 
     this.readFile("C:\\folder\\autoTrack.xlsx"); //this is where the program crash due to lack of permissions! 
    } 
    else 
    { 
     StatusLabel.Text = "Select a file to start the process!"; 
    } 

} 

还原C的ACL:\文件夹中的文件夹具有完全控制权限的网络服务,并且启用继承以传播到子对象。

另外我读了在应用程序池的“标识”选项卡中使用域帐户可以解决问题,但是如果将身份从预定义的网络服务更改为我的域用户,则尝试使用“服务不可用”达到我的申请。

对此的任何帮助真的很感激。

回答

0

首先,尝试在文件夹中授予Everyone权限以查看它是否有效。如果是这样,那么只需要找到授予正确权限的正确用户即可。如果你在IIS上运行,你应该授予应用程序池用户权限,如这里所述 - >http://www.iis.net/learn/manage/configuring-security/application-pool-identities

+0

感谢您的回复,我添加了具有完全权限的Everyone组,但仍得到相同的结果。我将应用程序池标识配置为通过网络服务进行身份验证,但没有成功(我正在运行IIS 6.0 BTW,您向我提供的教程适用于IIS 7.0) – Vito 2013-04-08 16:35:15