.NET System.IO.PathTooLongException from Web Application - c#

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.

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

Related

IIS express error500.24 web api

I migrate an dotnet framework web api application from vs 2010 to 2019.
I want to use IIS express for developpement mode debug.
My application is built with a api back in dotnet framework 4.5 using xml and not json and a front in dotnet winform.
sorry for the french messages.
thanks a lot for your suggest.
I've been stuck with this for a week
Vincent
I tried to change the web.config, the applicationhost.config (in the user iis express directory and the .VS\config directory.
add modules to IIS manager
Try removing this line from your web.config,
<identity impersonate="true"/>
Or,
as Described in here;
Your application's Web.config file specifies "identity
impersonate='true'".
In IIS 7 Integrated mode, client impersonation is not available in
some early request processing stages. Therefore, IIS will generate the
migration error message. If your ASP.NET Web application impersonates
client credentials (most common with intranet scenarios), you may want
to set the validateIntegratedModeConfiguration attribute to false.
Add this section to your config to overcome this issue,
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
thanks for your help
I have tried
validateIntegratedModeConfiguration="false"
and it worked only when I deleted the lines created in the applicationhost.config (but it's not a solution)
we finally found: the problem was that I modified the .csproj file; but the file used for the user configuration is the .csproj.user.
It is modified with the "property" tab of VS.
I had seen it in a post for an mvc web application, since we are using an api, I thought it was different because it is an api.....
My colleague showed me the options in the panel... and now it works!!!!
[]You have to modify in properties :
anonymous authentication : disable
windows authentication : enable
pipiline mode : classic
and that's all
Make sure all the following .NET modules are installed.
.NET SDK 6.0.100
.NET Runtime 6.0.0
.NET hosting 6.0.0
note that the above are the current versions the versions may differ.
also change the version of .config files by running as Administrator whether you open the .json on Notepad or your IDE.
make sure your Internet Information Services is up to date and have selected all features on IIS

.NET Core hosting to IIS, I get HTTP Error 500.30 - ANCM In-Process Start Failure

Problems deploying .NET Core to IIS.
I followed the steps as below:
Created a website using .NET Core 3.1 with Visual Studio
Created website inside IIS (pointing to an empty physical path C:\inetpub\mywebsite and address mywebsite.core.com)
Published my website from Visual Studio into the same folder, C:\inetpub\mywebsite
Host entry to browse from browser e.g. went to drivers\etc\hosts and added line
127.0.0.1 mywebsite.core.com
Installed bundles from here:https://dotnet.microsoft.com/download/dotnet-core/thank-you/runtime-aspnetcore-3.1.5-windows-hosting-bundle-installer
Error is:
HTTP Error 500.30 - ANCM In-Process Start Failure Common solutions to
this issue: The application failed to start The application started
but then stopped The application started but threw an exception during
startup Troubleshooting steps: Check the system event log for error
messages Enable logging the application process' stdout messages
Attach a debugger to the application process and inspect For more
information visit: https://go.microsoft.com/fwlink/?LinkID=2028265
I have a feeling this might be related to my launchSettings.json file, not sure how it should be adapted...
When I launched my site from Visual Studio it used to open directly to a swagger link, but now after publishing to IIS I can no longer launch it from Visual Studio (unable to connect to webserver IISExpress)...
Any help please?
It's a .NET Core 3.1 console app with a Startup that opened a swagger with my APIs before I attempted to publish to IIS.
Later edit:
https://learn.microsoft.com/en-us/aspnet/core/test/troubleshoot-azure-iis?view=aspnetcore-3.1 this suggests two possible causes: lack of permission to key vaults (not a preoblem, I am logged in Azure with azure cli); and the other one is: "The app is misconfigured due to targeting a version of the ASP.NET Core shared framework that isn't present. Check which versions of the ASP.NET Core shared framework are installed on the target machine."
Later edit:
The web.config from C:\inetpub\mywebsite looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\XXX.MyWebsite.Api.RestApi.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="outofprocess" />
</system.webServer>
</location>
</configuration>
I actually changed hostingModel="inprocess" to: hostingModel="outofprocess"
And my Project > Properties > Debug looks like this:
(as you can see I changed from In Process to Out of Process)
and the bindings in IIS look like this:
UPDATE: After all of this, my error changed to:
HTTP Error 502.5 - ANCM Out-Of-Process Startup Failure Common
solutions to this issue: The application process failed to start The
application process started but then stopped The application process
started but failed to listen on the configured port
(it was initially 500.30)
Not really sure what else to try. How do I check if the port is well configured?
Try to follow this article. https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/development-time-iis-support?view=aspnetcore-3.1
If it does not work - make sure that your application pool is enabled in IIS for you web application. Try also to restart IIS.
Debugging Via Kestrel Way
Kindly try to publish your application to a particular folder . Dotnet Core Cli Command for publishing. Below command publishes to "output" folder
dotnet publish -o output
After moving to publish folder via cd command . Type dotnet <project-name>.dll . Use your project name instead of <project-name>
your application should be running and it should be working perfectly . if you face any issue , it is due to application error
Deploy to IIS
After that for hosting your application to production or staging , Install IIS (not express) and
.NET core hosting bundle.[click here to download hosting bundle]
After that , you can follow this guide

Hosting multiple .net core using the same application pool with AspNetCoreModuleV2

Hi I am trying to host a multiple .net core 3 application using the same application pool in IIS
But were receiving ACME 500 error on the other application and only first one hosted is working
Does anyone know whats the reason behind this?
Note: We tried reducing the module version in webconfig "AspNetCoreModuleV2" to "AspNetCoreModule" and the others application worked but I dont want to use this solution.
One app per pool is the design limitation of ASP.NET Core module in-process hosting mode.
Sharing an app pool among apps isn't supported. Use one app pool per
app.
You either accept it, or switch to out-of-process mode (actually you did that by using the version 1 of ASP.NET Core module).
Two other alternatives are:
Option 1.
Open the .csproj file and add the below property to apply the proper hosting model.
<PropertyGroup>
...
<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
</PropertyGroup>
In ASP.NET Core apps we don't have web.config so first, we have to publish your application and in the published folder you can see there your web.config the file generated by .NET 5 Core. Now open the config file.like as given below.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\DotNetCoreApp.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="OutOfProcess" />
</system.webServer>
</location>
</configuration>
The In-process hosting model is the default model. So if you want to change it to other i.e. Out-of-process then you just need to change hostingModel="OutOfProcess".
Option 2.
In VS2019
Close your solution
Delete applicationhost.config in folder .vs or delete the whole .vs folder. The .vs is a hidden folder and is next to your solution file usually.
Restart your solution again
I tried running multiple sites sharing same application pool and it worked fine, but then sometimes it behaves strangely so better to have separate application pool.
For example you may encounter following error:
Asp.Net Core 2.2 - HTTP Error 500.0 - ANCM In-Process Handler Load
Failure
To avoid such issues create separate application pool for each .NET Core site.
https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-2.2#in-process-hosting-model
Sharing an app pool among apps isn't supported. Use one app pool per
app.
I faced this issue recently, wanted to add my solution here so it can be helpful to others.
My site was hosted on Plesk based windows hosting and after publishing, I faced this issue
HTTP Error 500.35 - ASP.NET Core does not support multiple apps in the same app pool
Common solutions to this issue:
Select a different app pool to host this app.
I solved it by enabling Dedicated IIS App pool for the site in Plesk dashboard. It is not enabled by default.

Deploying .NET Core 2.1 web application

I'm trying to deploy a .NET Core web application, and what happens is that I'm constantly getting a 500 server error
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.
Regardless of what I put into the file system folder (I tried 3 different .NET Core web apps), there's always this error. I tried standard Visual Studio "Hello world" application - same thing. Logs are not created, this is the sample entry from the web.config file being used:
<aspNetCore processPath="dotnet" arguments=".\TestAppMin.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
I manually created logs/stdout folder and changed IIS app pool rights to it - read/write.
IIS pool is configured as "No managed code" and "Integrated" pipeline.
I tried debug and release mode - no avail. I changed exception handling to custom in Startup.cs - still 500 error.
Latest .NET Core SDK is installed on the server.
If I manually create default.htm file, it's being displayed properly.
Can someone please advise me what am I doing wrong? Is there a way to diagnose that?
Thank you!
Do you have enabled AspNetCore Module in IIS under Handler Mappings ? I got it on first position.

Integrated managed pipeline mode Error in VS15

I was a user of visual studio 2012 but now i get switched to visual studio 2015.
Newly developed applications are working and running fine on development server but when I open old .Net applications and runs them it's generating error given below:
An ASP.NET setting has been detected that does not apply in Integrated
managed pipeline mode.
How can I resolve this ?
Can anyone help me please?
I just Added the following lines in web.config file under configuration TAG :
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
Follow the answer in this SO thread
There are three options to solve this.
Change the Application Pool mode to one that has Classic pipeline enabled.
In web.config / web app will need to be altered to support Integrated pipelines. Normally this is as simple as removing parts of your web.config.
Add the following to your web.config.

Categories

Resources