Web应用程序中的.NET System.IO.PathTooLongException [英] .NET System.IO.PathTooLongException from Web Application

查看:191
本文介绍了Web应用程序中的.NET System.IO.PathTooLongException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Windows 10和Windows Server 2016引入了解决传统长路径问题的解决方案.该解决方案易于实现,在以下

Windows 10 and Windows Server 2016 introduce solution for the traditional Long Path issue. The solution is straightforward to implement and detailed very good in the following blog post. Following the steps works successfully for a .NET console/desktop application. However, for some reason, when running the same code from a ASP.NET web application I still getting the same classic System.IO.PathTooLongException exception.

引发异常的代码:

Directory.CreateDirectory(longPath);

正如我提到的那样,该代码在控制台应用程序上成功运行,但是在ASP.NET网站应用程序中失败.网站web.config包括以下内容:

As I mention, the code runs successfully on console application, but fails in ASP.NET website application. the website web.config includes the following:

<?xml version="1.0"?>
<configuration>
  <runtime>
    <AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false;Switch.System.IO.BlockLongPaths=false"/>
  </runtime>
</configuration>

和应用程序清单文件,如上面的博客链接所述.

and application manifest file as explained in the blog link above.

任何想法表示赞赏.

推荐答案

感谢@ bradbury9,它指出了类似的问题,我确认应用程序无法在运行时加载开关长路径阻塞设置.此外,由于我的应用程序基于.NET 4.5.1的版本,因此无法使用

Thanks to @bradbury9 that point me to similar issue, I confirmed that the application failed to load the switch long-path blockage settings in run-time. In addition, because the version of my application based on .NET 4.5.1, it's impossible to use the AppContext class for manually set the desired switches programmatically.

解决方案:

对于基于.NET 4.6.1或更低版本的ASP.NET Web应用程序,请确保在运行该应用程序的计算机上还安装了.NET 4.6.2,并在httpRuntime配置.

For ASP.NET web application, based on .NET 4.6.1 or below, make sure that .NET 4.6.2 is also installed on the machine that runs the application, and add the following attribute targetFramework="4.6.2" the the httpRuntime configuration.

示例:

<system.web>
    <httpRuntime targetFramework="4.6.2" />
    <compilation targetFramework="4.5.1" />
</system.web>

*请注意,支持长路径的Windows(例如Windows Server 2016和Windows 10)将已安装.NET 4.6.2

* Please notice that Windows that supports Long Path, such Windows Server 2016 and Windows 10, will have already .NET 4.6.2 installed

这篇关于Web应用程序中的.NET System.IO.PathTooLongException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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