.NET System.IO.PathTooLongException from Web Application

て烟熏妆下的殇ゞ 提交于 2019-12-24 07:54:28

问题


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.

The code that throws exception:

Directory.CreateDirectory(longPath);

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.

Any idea appreciated.


回答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.

Solution:

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.

Example:

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

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



来源:https://stackoverflow.com/questions/45476852/net-system-io-pathtoolongexception-from-web-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!