日期:2014-05-17  浏览次数:21015 次

C# 我想要在网页上下载图片,但是当运行到System.IO.File.Create(savePath);时,出错:对路径“D:\”的访问被拒绝。
 savePath = "D:\\";
if (File.Exists(savePath)) File.Delete(savePath);
            outStream = System.IO.File.Create(savePath);
            inStream = response.GetResponseStream();
具体显示错误:

异常详细信息: System.UnauthorizedAccessException: 对路径“D:\”的访问被拒绝。

ASP.NET 未被授权访问所请求的资源。请考虑授予 ASP.NET 请求标识访问此资源的权限。ASP.NET 有一个在应用程序没有模拟时使用的基进程标识(通常,在 IIS 5 上为 {MACHINE}\ASPNET,在 IIS 6 上为网络服务)。如果应用程序正在通过 <identity impersonate="true"/> 模拟,则标识将为匿名用户(通常为 IUSR_MACHINENAME)或经过身份验证的请求用户。

要将 ASP.NET 访问权限授予某个文件,请在资源管理器中右击该文件,选择“属性”,然后选择“安全”选项卡。单击“添加”添加适当的用户或组。突出显示 ASP.NET 帐户,选中所需访问权限对应的框。

源错误:


行 165:        {
行 166:            if (File.Exists(savePath)) File.Delete(savePath);
行 167:            outStream = System.IO.File.Create(savePath);
行 168:            inStream = response.GetResponseStream();
行 169:            int l;


源文件: d:\GXX-WORKDISK\project\zzqz\download.aspx.cs    行: 167

堆栈跟踪:


[UnauthorizedAccessException: 对路径“D:\”的访问被拒绝。]
   System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +7717551
   System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) +1162
   System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) +65
   System.IO.File.Create(String path) +37
   download.SaveBinaryFile(WebResponse response, String savePath) in d:\GXX-WORKDISK\project\zzqz\download.aspx.cs:167
   download.DownloadPicture(String picUrl, String savePath, Int32 timeOut) in d:\GXX-WORKDISK\project\zzqz\download.aspx.cs:149
   download.Page_Load(Object sender, EventArgs e) in d:\GXX-WORKDISK\project\zzqz\download.aspx.cs:51
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.EventHandler.Invoke(Object sender, EventArgs e) +0
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627


求解啊!!!!!!
<