Directory.CreateDirectory 在共享主机上抛出 UnauthorizedAccessException 的可能原因

发布于 2024-10-09 10:00:52 字数 1246 浏览 0 评论 0原文

我目前正在开发一个 ASP.NET 3.5 / IIS7 应用程序,我使用 WinHost 作为临时托管环境。我正在观看一些戏剧,我认为这些戏剧存在权限问题,而且票务流程刚刚达到“你自己做”的阶段。

这就是我想要做的:

var dir = Server.MapPath("~/MyFolder/NewPath");
Directory.CreateDirectory(dir);

这是我得到的回应:

访问路径 'E:\web\MyAccount\MyFolder\NewPath' 是 被拒绝。

描述:未处理的异常 执行期间发生的 当前的网络请求。请查看 堆栈跟踪以获取有关的更多信息 错误及其起源 代码。

异常详细信息: 系统未授权访问异常: 访问路径 'E:\web\MyAccount\MyFolder\NewPath' 是 被拒绝。

堆栈跟踪显示 CreateDirectory 行失败。该应用程序在本地运行良好,并且应用程序池运行的身份具有对“MyFolder”路径的写访问权限。在这两种环境中,信任级别均设置为“完全”。

WinHost 的指导是:

默认情况下,asp.net 用户拥有完整的权限 您网站的权限。

进一步观察,WindowsIndentity.GetCurrent().Name 返回“W02\aspnet_17884”,这似乎是帐户特定的标识。我的感觉是,该帐户无权写入应用程序的文件系统,但当我提示 WinHost 时,我收到:

您遇到的问题是 与您的申请相关 配置。

我建议做的是 注册然后发布您的 DiscountASP.NET 中的问题 社区论坛

这显然就是为什么现在这个问题出现在 Stack Overflow 上的原因:)

任何人都可以建议任何应用程序级别的配置更改吗?这更有可能是托管站点上的权限问题吗?谢谢。

更新:我还将问题提出到 WinHost 论坛

I'm currently working on an ASP.NET 3.5 / IIS7 app for which I'm using WinHost as a temporary hosting environment. I'm having some dramas with what I believe are permissions issues and the ticketing process has just reached "you're on your own" stage.

Here's what I'm trying to do:

var dir = Server.MapPath("~/MyFolder/NewPath");
Directory.CreateDirectory(dir);

And here's the response I'm getting:

Access to the path
'E:\web\MyAccount\MyFolder\NewPath' is
denied.

Description: An unhandled exception
occurred during the execution of the
current web request. Please review the
stack trace for more information about
the error and where it originated in
the code.

Exception Details:
System.UnauthorizedAccessException:
Access to the path
'E:\web\MyAccount\MyFolder\NewPath' is
denied.

The stack trace shows the CreateDirectory line failing. The app runs fine locally and the identity the app pool is running under has write access to the "MyFolder" path. In both environments, the trust level is set to "Full".

The guidance from WinHost is:

By default the asp.net user has full
permissions to your site.

Looking further into it, WindowsIndentity.GetCurrent().Name returns "W02\aspnet_17884" which appears to be an account specific identity. My feeling is that this account does not have access to write to the file system of the app but when I prompted WinHost on this I received:

The problem you are running into is
related to your application
configuration.

and

What I'd recommend doing is
registering and then posting your
question in the DiscountASP.NET
Community Forum

Which is obviously why the question is now on Stack Overflow :)

Can anyone suggestion any app level configuration changes? Is this more likely a permissions issue on the hosting site? Thanks.

Update: I've also put the question up on the WinHost forum.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倾`听者〃 2024-10-16 10:00:52

答案是……网络部署破坏了它。实际上,严格来说,答案是权限根本不存在(如预期),但原因似乎是 Web 部署以某种方式删除了写入权限。我可以从具有发布 ACL 能力的 Web 部署的角度看到这一点,但为什么 WinHost 允许它操纵包含网站的目录的权限超出了我的范围。

有关我的问题(以及 WinHost 的回复)的更多信息,请访问他们的论坛,主题为 No write access到文件系统

And the answer is... web deploy broke it. Actually, the answer is strictly that the permissions simply weren't there (as expected), but the cause appears to be that web deploy somehow removed the write permissions. I can see this from the perspective of web deploy having the ability to publish ACLs, but why WinHost allows this to manipulate the permissions of the directory containing the website is beyond me.

Further info on my question (and WinHost's response), is on their forum under the thread No write access to file system.

ぶ宁プ宁ぶ 2024-10-16 10:00:52

是的,“W02\aspnet_17884”应该有足够的权限来创建文件夹。我建议您在 ASPSPIDER 上创建一个免费帐户,并在那里上传一个非常简单的示例,其配置与您的配置类似。如果该方法在那里有效,但在 WinHost 上无效,您可以向他们展示它如何在 assppider 上工作,但在他们的服务器上无效。然后强迫他们解决或获得新的主机。

Yes, "W02\aspnet_17884" should have enough permission to create folder. I would suggest you to create a free account on ASPSPIDER and upload a very simple sample there with configuration similar to yours. If that works there and not on WinHost, you can show them how it is working on aspspider but not on their server. Then force them to resolve or get a new host.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文