2010-05-07 52 views
-2

我正试图写入我的网站上的文件。但是,当试图用这一行打开文件时: fileName = HostingEnvironment.ApplicationPhysicalPath +“lala.htm”;asp.net tryint写入服务器上的文件

我得到这个异常: (它得到正确的道路,但仍不允许我写的话)

访问路径“d:\ DZHosts \ LocalUser \ asafz83 \ WWW .asafz83.somee.com \ lala.htm'被拒绝。 描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关该错误的更多信息以及源代码的位置。

异常详细信息:System.UnauthorizedAccessException:对路径'd:\ DZHosts \ LocalUser \ asafz83 \ www.asafz83.somee.com \ lala.htm'的访问被拒绝。

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

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

源错误:

在当前web请求的执行过程中生成未处理的异常。关于异常的来源和位置的信息可以使用下面的异常堆栈跟踪来标识。

堆栈跟踪:

[UnauthorizedAccessException:访问路径 'd:\ DZHosts \ LocalUser \ asafz83 \ www.asafz83.somee.com \ lala.htm'。被拒绝] System.IO .__错误(Int32 errorCode,String maybeFullPath)+7716639 System.IO.FileStream.Init(String path,FileMode mode,FileAccess access,Int32 rights,Boolean useRights,FileShare share,Int32 bufferSize,FileOptions选项,SECURITY_ATTRIBUTES secAttrs,String msgPath,布尔型bFromProxy)+1162 System.IO.FileStream..ctor(String path,FileMode mode,FileAccess access,FileShare share,Int32 bufferSize,FileOptions options)+65 System.IO.StreamWriter.CreateFile(String path, +58 System.IO.StreamWriter.ctor(String path,Boolean append,Encoding encoding,Int32 bufferSize)+58 System.IO.StreamWriter..ctor(String path,Boolean append)+33 Class1。在C:\ Documents and Settings \אסףאזולאי\ My Documents \ Visual Studio 2008 \ Projects \ WebSite6 \ Class1 \ httpFilter.cs中的HTTPFilter.Init(HttpApplication上下文):50 System.Web.HttpApplication.InitModulesCommon()+65 System .Web.HttpApplication.InitModules()43 System.Web.HttpApplication.InitInternal(HttpContext的上下文中,HttpApplicationState状态,MethodInfo的[]处理程序)729 System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext的上下文中)298 的System.Web .HttpApplicationFactory.GetApplicationInstance(HttpContext上下文)+107 System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)+289

HELP请... 任何人...

+0

请重新格式化您问题中的代码(例如'fileName = HostingEnvironment.ApplicationPhysicalPath +“lala.htm”;'它会使它更具可读性,而@Darin Dimitrov表示,解决方案似乎处于异常/问题?!? – scherand 2010-05-07 09:15:17

回答

0

你不读异常消息:

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 , 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.

因此授予写权限ASPNET帐户到d:\DZHosts\LocalUser\asafz83\www.asafz83.somee.com文件夹。

+0

我不是愚蠢的,没有选择授予它正确的访问权限,正如他在第二段中所说的那样,你明智地引用了它的内容 有人知道如何解决这个问题... – asaf 2010-05-07 09:13:17

+0

我必须为什么你不能选择授予对ASP.NET身份文件的写入权限? – 2010-05-07 09:18:47

+0

@asaf,你对目标机器有管理权限吗? – 2010-05-07 09:20:58