上传图片

时间:2011-01-16 15:59:56

标签: asp.net

大家好,我的网站有问题。当我使用我的本地主机上传图片时,它工作正常,但当我尝试从互联网上传图片时,我有以下错误消息:

服务器错误。

访问路径'D:\ Hosting \ 4423045 \ html \ please-god \ UploadedImages \ 3.jpg'被拒绝。 描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息:System.UnauthorizedAccessException:拒绝访问路径'D:\ Hosting \ 4423045 \ html \ please-god \ UploadedImages \ 3.jpg'。

ASP.NET无权访问所请求的资源。考虑将资源的访问权限授予ASP.NET请求标识。 ASP.NET具有基本进程标识(通常是IIS 5上的{MACHINE} \ ASPNET或IIS 6上的网络服务),如果应用程序未模拟,则使用该标识。如果应用程序模拟通过,则标识将是匿名用户(通常为IUSR_MACHINENAME)或经过身份验证的请求用户。

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

来源错误:

Line 21:             If imageUpload.HasFile Then
Line 22:                 Dim baseDirectory As String = Server.MapPath("~/UploadedImages/")
Line 23:                 imageUpload.SaveAs(baseDirectory & pictureIDJustAdded & ".jpg")
Line 24:             End If
Line 25:         End If

源文件:D:\ Hosting \ 4423045 \ html \ please-god \ PhotoAdmin \ Default.aspx.vb Line:23

堆栈追踪:

[UnauthorizedAccessException: Access to the path 'D:\Hosting\4423045\html\please-god\UploadedImages\3.jpg' is denied.]
   System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +7715167
   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, String msgPath, Boolean bFromProxy) +61
   System.IO.FileStream..ctor(String path, FileMode mode) +55
   System.Web.HttpPostedFile.SaveAs(String filename) +99
   System.Web.UI.WebControls.FileUpload.SaveAs(String filename) +23
   PhotoAdmin_Default.dvPictureInsert_ItemInserted(Object sender, DetailsViewInsertedEventArgs e) in D:\Hosting\4423045\html\please-god\PhotoAdmin\Default.aspx.vb:23
   System.Web.UI.WebControls.DetailsView.OnItemInserted(DetailsViewInsertedEventArgs e) +108
   System.Web.UI.WebControls.DetailsView.HandleInsertCallback(Int32 affectedRows, Exception ex) +69
   System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) +134
   System.Web.UI.WebControls.DetailsView.HandleInsert(String commandArg, Boolean causesValidation) +274
   System.Web.UI.WebControls.DetailsView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +676
   System.Web.UI.WebControls.DetailsView.OnBubbleEvent(Object source, EventArgs e) +95
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.DetailsViewRow.OnBubbleEvent(Object source, EventArgs e) +113
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +118
   System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +135
   System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

1 个答案:

答案 0 :(得分:2)

您需要将IIS用户的权限授予该目录。错误消息提供了有关如何操作的信息,但下面有更多信息

此处有更多信息 - http://www.webdeveloper.com/forum/showthread.php?t=131624

https://stackoverflow.com/search?q=Exception+Details%3A+System.UnauthorizedAccessException