我嘗試從本地網絡中的共享文件夾訪問文件時遇到問題。
當我在Visual Studio中運行應用程序時,它工作正常,我可以下載該文件,但是當我將應用程序部署到IIS時,它根本不起作用。
我不明白爲什麼,因爲我給予所有用戶的完全權限,包括NETWORK SERVICE和IIS_USR。
我正在使用我的電腦進行測試。它具有Windows 7並運行IIS 7.5。我嘗試訪問的共享文件夾位於未安裝IIS的Windows Vista安裝中。從IIS中部署的應用程序訪問共享文件夾
下載文件的代碼是這樣的:
protected void button_Click(object sender, EventArgs e)
{
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=S10.png");
Response.WriteFile(@"\\192.168.1.82\Machine\file.png");
Response.End();
}
,它給我下面的錯誤:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.UnauthorizedAccessException: Acesso negado ao caminho '\192.168.1.82\Machine\file.png'.
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 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.
To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.
請有人可以幫助我。 在此先感謝。
Thaks您的回覆,但it's不是那個意思,我檢查了共享權限和it's罰款,這也適用於Visual Studio中運行良好,但只有當我運行在IIS中的應用程序給我的問題。 – Luis 2012-04-23 19:46:41
回覆編輯後發表評論。 – 2012-04-23 20:11:45
感謝您的幫助。我已經嘗試過,並沒有工作,總是得到相同的錯誤,無法找出問題所在。 – Luis 2012-04-24 15:47:32