使用 ASP.NET 4.0 项目保存图像时访问路径被拒绝
我有一个用 .NET 3.5 编写的现有应用程序。有问题的代码片段使用 FileUpload 控件及其 SaveAs 方法。它在过去六个月中运行良好,但我最近将项目升级到 .NET 4.0,现在每次调用该方法时都会收到“访问路径 (...) 被拒绝”的消息。它在开发模式下在本地工作正常,但在我的产品服务器上失败。我已将网站升级为在 .NET 4.0 下运行,并确保它在应用程序池中运行的帐户(网络服务)具有完全控制权。除了升级到 .NET 4.0 之外,该项目没有任何变化。有什么想法或建议吗?提前致谢。
I have an existing application that was written in .NET 3.5. The piece of code in question is using the FileUpload control and its SaveAs method. Its worked perfectly for the past six months, but I've recently upgraded the project to .NET 4.0 and I'm now receiving an "Access to path (...) is denied" every time the method is called. It works fine locally in dev mode but fails on my prod server. I've upgraded the website to run under .NET 4.0 and I've made sure the account (Network Service) it runs under in the app pool has full control. Other than upgrading to .NET 4.0, nothing has changed for the project. Any ideas or suggestions? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,我要做的是通过(暂时)授予“每个人”对该路径的访问权限来仔细检查这确实是一个权限问题。运行快速测试...如果有效,那么您肯定会遇到权限问题。
接下来,查看 EventViewer 中的异常,它应该告诉您尝试写入文件的用户身份。如果这不起作用,您可以使用 FileMon 查看尝试日志,并从中获取所需的信息。
这些问题令人头疼,99% 的问题是 Microsoft 在每次 IIS 或 .NET 更新中改变了它的工作方式。如果版本与版本之间保持一致,则永远不会出现这种情况。
First, what I would do is double-check that this is really a permissions issue by (TEMPORARILY) granting "Everyone" access to that path. Run a quick test... if it works, you're definitely looking at a permissions issue.
Next, look at the exception in EventViewer and it should tell you the user identity that is attempting to write the file. If that doesn't work, you can use FileMon to see a log of the attempt and definitely get the info you need from that.
These issues are a pain in the ass, and 99% of the issue is that Microsoft changes the way this works in every IIS or .NET update. If it was just consistent from version to version, this would never crop up.