ASP.net 收到错误“访问路径被拒绝".在尝试将文件上传到我的 Windows Server 2008 R2 Web 服务器时 [英] ASP.net Getting the error "Access to the path is denied." while trying to upload files to my Windows Server 2008 R2 Web server

查看:36
本文介绍了ASP.net 收到错误“访问路径被拒绝".在尝试将文件上传到我的 Windows Server 2008 R2 Web 服务器时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个将文件上传到 Web 服务器上的特定文件夹的 asp.net Web 应用程序.本地一切正常,但是当我将应用程序部署到 Web 服务器时,我开始收到错误访问路径D:Attachmentsmyfile.doc"被拒绝".我向IIS AppPool"用户提供了该应用程序在该文件夹的完全权限下运行的信息.我什至给了所有人"完全权限,但出现了同样的错误.

I have an asp.net webapplication that uploads files to a specific folder on the Web server. locally everything works fine, but when I deploy the application to the Webserver, I begin getting the error "Access to the path "D:Attachmentsmyfile.doc" is denied". I gave the "IIS AppPool" user that the application is running under full permission on the folder. I even gave "Everyone" full permissions, but with the same error.

我将该文件夹添加到 Antivirus 的例外列表中,但结果相同.我开始怀疑 Windows Server 2008 R2 可能需要一个技巧才能让我的上传工作.非常感谢您的帮助.

I added the folder to the Exceptions list of the Antivirus, but with the same result. I am begining to suspect that maybe Windows Server 2008 R2 needs a trick for my upload to work. I really appreciate your help.

谢谢

推荐答案

您的 asp.net 帐户 {MACHINE}ASPNET 没有对该位置的写入权限.这就是它失败的原因.

Your asp.net account {MACHINE}ASPNET does not have write access to that location. That is the reason why its failing.

考虑向 ASP.NET 请求标识授予对资源的访问权限.

Consider granting access rights to the resource to the ASP.NET request identity.

右键单击下载文件夹 Properties >安全选项卡编辑 >添加 >地点 >选择您的本地机器 >单击确定">在输入要选择的对象名称"下方键入 ASPNET >单击检查名称选中所需访问权限的复选框(完全控制).如果它对您不起作用,请使用 Network Service

Right click on downloading folder Properties > Security Tab > Edit > Add > locations > choose your local machine > click OK > Type ASPNET below "Enter the object name to select" > Click Check Names Check the boxes for the desired access (Full Control). If it will not work for you do the same with Network Service

现在这应该显示您的本地 {MACHINENAME}ASPNET 帐户,然后您为此帐户设置写入权限.

Now this should show your local {MACHINENAME}ASPNET account, then you set the write permission to this account.

否则,如果应用程序通过 <identity impersonate="true"/> 进行模拟,则身份将为匿名用户(通常为 IUSR_MACHINENAME)或经过身份验证的用户请求用户.

Otherwise if the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

或者只是使用专用位置来存储 ASP.NET 中的文件,即 App_Data.要创建它,请右键单击您的 ASP.NET 项目(在 Visual Studio 中)Add >添加 ASP.NET 文件夹 >应用数据.然后你就可以将数据保存到这个位置:

Or just use dedicated location for storing files in ASP.NET which is App_Data. To create it right click on your ASP.NET Project (in Visual Studio) Add > Add ASP.NET Folder > App_Data. Then you'll be able to save data to this location:

var path = Server.MapPath("~/App_Data/file.txt");
System.IO.File.WriteAllText(path, "Hello World");

这篇关于ASP.net 收到错误“访问路径被拒绝".在尝试将文件上传到我的 Windows Server 2008 R2 Web 服务器时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆