下面的代码用于我的网站插入照片,在我的计算机上,我可以插入照片,但是当我将它传输到远程机器时,我收到错误消息。这是代码:
Protected Sub dvPictureInsert_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs) Handles dvPictureInsert.ItemInserted
'If the record was successfully inserted, save the picture
If e.AffectedRows > 0 Then
'Determine the maximum pictureID for this user
Dim results As DataView = CType(maxPictureIDDataSource.Select(DataSourceSelectArguments.Empty), DataView)
Dim pictureIDJustAdded As Integer = CType(results(0)(0), Integer)
'Reference the FileUpload control
Dim imageUpload As FileUpload = CType(dvPictureInsert.FindControl("imageUpload"), FileUpload)
If imageUpload.HasFile Then
Dim baseDirectory As String = Server.MapPath("~/UploadedImages/")
imageUpload.SaveAs(baseDirectory & pictureIDJustAdded & ".jpg")
End If
这是错误消息:
“/please-god”应用程序中的服务器错误。拒绝访问路径“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 帐户,然后选中所需访问权限的框。
源错误:
第 21 行:如果 imageUpload.HasFile 则第 22 行:
将 baseDirectory 作为 String = Server.MapPath("~/UploadedImages/") 进行调暗 第 23 行:
imageUpload.SaveAs(baseDirectory & pictureIDJustAdded & ".jpg") 第 24 行:如果第 25 行结束: End If 源文件:D:\Hosting\4423045\html\please-god\PhotoAdmin\Default.aspx.vb 行:23堆栈跟踪:
[UnauthorizedAccessException: 访问路径 'D:\Hosting\4423045\html\please-god\UploadedImages\3.jpg' 被拒绝。]
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路径、FileMode 模式、FileAccess 访问、FileShare 共享、Int32 bufferSize、FileOptions 选项、String msgPath、Boolean bFromProxy) +61 System.IO.FileStream..ctor(String path, FileMode 模式) +55
System.Web.HttpPostedFile.SaveAs(字符串文件名)+99
System.Web.UI.WebControls.FileUpload.SaveAs(String filename) +23
PhotoAdmin_Default.dvPictureInsert_ItemInserted(Object sender, DetailsViewInsertedEventArgs e) 在 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 值, DataSourceViewOperationCallback 回调)+134
System.Web.UI.WebControls.DetailsView.HandleInsert(String commandArg,Boolean CauseValidation)+274 System.Web.UI.WebControls.DetailsView.HandleEvent(EventArgs e,Boolean CauseValidation,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(对象源,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(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint) + 1565