2013-04-08 97 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