.Net Core IIS 程序报错 Access to the path c:\\windows\\TEMP\\poifiles is denied

程序运行报错:Access to the path c:\\windows\\TEMP\\poifiles is denied , 此错误本文介绍两种解决办法,选择适合你的方法即可;一般.Net程序运行方案二可能比较常用。

解决方案一:

从 IIS 访问文件系统

如果您在浏览托管在 IIS 上的网站时遇到此错误,则该错误与上面描述的错误类似。托管在 IIS 上的 .NET 应用程序默认使用应用程序池用户来访问文件系统上的文件。

要解决此问题,请右键单击文件夹并选择 "属性" ,将 IIS 应用程序池 用户添加到应用程序的根文件夹。选择 "安全" 选项卡并添加 IIS 应用程序池*<* 应用程序池名称*>* 用户:

与 Windows 服务一样,您也可以决定创建自定义用户以从 IIS 访问文件系统。创建一个新的 Windows(或 AD)用户,然后在 IIS 管理器中单击您的站点。在 "操作" 窗口中单击 "基本设置" 。最后,单击 "连接为"按钮并在 "特定用户" 下输入新用户 :

此示例说明了 IIS 用户无权访问包含网站文件的文件夹的情况。您可能还会遇到其他情况,其中使用 Windows 身份验证来控制单个网站用户对文件系统上的一个或多个文件的访问。在这些情况下,您需要重复使用上述示例来捕获代码中的异常,并以比显示 IIS 错误页面更好的方式通知网站用户。

解决方案二(一般常用):

bash 复制代码
System.UnauthorizedAccessException: Access to the path 'C:\Windows\TEMP\ASPNETCORE_935a19f1-814f-4b33-831d-7c6a7b988e43.tmp' is denied.
   at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
   at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
   at System.IO.Strategies.FileStreamHelpers.ChooseStrategyCore(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
   at System.IO.Strategies.FileStreamHelpers.ChooseStrategy(FileStream fileStream, String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, Int64 preallocationSize)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at Microsoft.AspNetCore.WebUtilities.FileBufferingReadStream.CreateTempFile()
   at Microsoft.AspNetCore.WebUtilities.FileBufferingReadStream.ReadAsync(Memory`1 buffer, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.WebUtilities.StreamHelperExtensions.DrainAsync(Stream stream, ArrayPool`1 bytePool, Nullable`1 limit, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Http.Features.FormFeature.InnerReadFormAsync(CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Http.Features.FormFeature.ReadForm()
   at Microsoft.AspNetCore.Http.DefaultHttpRequest.get_Form()

IIS运行的.net core程序正常,但有些功能报错:

System.UnauthorizedAccessException: Access to the path 'C:\Windows\TEMP\ASPNETCORE_e5e0d4d2-f4bf-446c-99c5-096b856b1cc8.tmp' is denied

有网上文章提示解决方案:

提示需要再网站对应 的应用程序池将 高级设置中 "加载用户文件配置" 设置为True 。

找到项目的应用程序池,将高级设置中"加载用户配置文件"(Load User Profile)设置为true即可。

相关推荐
shepherd枸杞泡茶18 小时前
第3章 3.3日志 .NET Core日志 NLog使用教程
c#·asp.net·.net·.netcore
csdn_aspnet18 小时前
ASP.NET Core 简单文件上传
asp.net·.netcore
亦世凡华、2 天前
掌握.NET Core后端发布流程,如何部署后端应用?
经验分享·.netcore·docker部署·程序发布
contact973 天前
.NET Core中的五种过滤器详解
.netcore·过滤器
以为不会掉头发的詹同学3 天前
【 Avalonia UI 语言国际化 I18n】图文结合教学,保姆级教学,语言国际化就是这么简单(.Net C#)
开发语言·前端·c#·.netcore·用户界面
爱吃香蕉的阿豪5 天前
在c#中虚方法和抽象类的区别
深度学习·c#·.netcore
shepherd枸杞泡茶5 天前
第3章 .NETCore核心基础组件:3.1 .NET Core依赖注入
开发语言·c#·.net·.netcore
.NET快速开发框架5 天前
使用nvm管理node.js版本,方便vue2,vue3开发
vue·.netcore·常用工具·开发技术·rdif
csdn_aspnet7 天前
ASP.NET Core 使用 FileStream 将 FileResult 文件发送到浏览器后删除该文件
asp.net·.netcore
csdn_aspnet7 天前
ASP.NET Core SixLabors.ImageSharp v1.0 的图像实用程序类 web示例
asp.net·.netcore