HTTP 500.19 – configuration data is invalid - c#

I created web service application on .net Core 2.2, it works fine on VS IIS Express, but windows server 2012 IIS 8 it throwing error :
The requested page cannot be accessed because the related configuration data for the page is invalid
I checked config file which was generated in published version and it was :
<?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=".\WebServices.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: 2ffcb152-3fb6-43b8-aa45-784eed3432bf-->
I checked it in online validator and it was ok, so i have no clue.

Related

ASP.NET Core 3.1 application having InProcess hosting model is getting timeout after 1 minute

What should be done if we want to increase the request timeout for asp.net core 3.1 application with InProcess hosting model? Our application is getting timed out in such scenarios.
We tried setting requestTimeout property in web.config but as written in link (https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-3.1#in-process-hosting-model), it is getting ignored.
So we are not sure what can be done for the same, please help.
Thanks
Hardik
Add web.config file to your project and write like these codes on it.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore requestTimeout="00:20:00" processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>
You can read more on here

Azure - Remove server" and "x-powered-by" .net core 3.1

I'm deploying a webapi (.net core 3.1) in Azure.
I read this articles...
How to remove x-powered-by header in .net core 2.0
and
Remove HTTP header on ASP.Net Core 2.2 InProcess
I created the web.confi, and de output when i publish, the file are created here "...\obj\Debug\netcoreapp3.1\PubTmp\Out" wiht this structed:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<security>
<requestFiltering removeServerHeader="true" />
</security>
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
</customHeaders>
</httpProtocol>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\xdws.dll" stdoutLogEnabled="false" stdoutLogFile="\\?\%home%\LogFiles\stdout" hostingModel="inprocess" />
</system.webServer>
</configuration>
However, still present the "server" and "x-powered-by" information, like this image.
image info

Visual Studio 2019 IIS profile creates web.config file that breaks Azure App Service

When creating a new Debug profile with Microsoft Visual Studio Community 2019 Version 16.6.3 on a ASP.NET Core Web 3.1 project a web.config file is created.
The file 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="C:\Users\<USER>\Source\Project\Project.Web\bin\Debug\netcoreapp3.1\Project.Web.exe" arguments="" stdoutLogEnabled="false" hostingModel="InProcess">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
</configuration>
Errors present when accessing the site with web.config:
AggregateException: One or more errors occurred. (One or more errors
occurred. (The NPM script 'start' exited without indicating that the
create-react-app server was listening for requests. The error output
was: )) System.Threading.Tasks.Task.ThrowIfExceptional(bool
includeTaskCanceledExceptions)
InvalidOperationException: The NPM script 'start' exited without
indicating that the create-react-app server was listening for
requests. The error output was:
Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer.ReactDevelopmentServerMiddleware.StartCreateReactAppServerAsync(string
sourcePath, string npmScriptName, ILogger logger)
I first thought that the exact aspNetCore processPath was the culprit but given the error it more looked like code from Startup.cs.
if (env.IsDevelopment())
{
spa.UseReactDevelopmentServer(npmScript: "start");
}
Looking at the actual file deployed it confirmed my suspicions, the path was relative here.
I needed to set ASPNETCORE_ENVIRONMENT as Production. Solved this by creating a new web.release.config file since I needed to test the application on an actual IIS with ASPNETCORE_ENVIRONMENT as Development. With this transformation everything worked:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!-- To customize the asp.net core module uncomment and edit the following section.
For more info see https://go.microsoft.com/fwlink/?linkid=838655 -->
<!--
<system.webServer>
<handlers>
<remove name="aspNetCore"/>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
-->
<location>
<system.webServer>
<aspNetCore>
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" xdt:Locator="Match(name)" xdt:Transform="SetAttributes" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
</configuration>
Source:
https://stackoverflow.com/a/54702411/3850405

Error while hosting .net core 3.0 in IIS (0x8007000D)

I created a website and it has the following web.config file. It is running in .net core 3.0 Self contained published version. It was running ago in Windows 7 now my company updated to windows 10 and now it stopped working. It is same IIS configuration but can't read the web.config file. I tried other solutions mentioned but I will love to have your support. It is giving error stating IIS can't load the webconfig file.
<?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=".\ASU_Statistics.exe" arguments="" stdoutLogEnabled="false" hostingModel="InProcess" stdoutLogFile=".\logs\stdout">
<environmentVariables>
<environmentVariable name="ASPNETCODE_ENVIRONMENT" value="Production" />
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
<environmentVariable name="ASPNETCORE_HTTPS_PORT" value="44370" />
<environmentVariable name="COMPLUS_ForceENC" value="1" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: ee398fc0-8f34-4edf-9353-67342cbe9ee3-->
Check that the AspNetCoreModuleV2 module is installed on server.
If module is not installed download AspNetCoreModuleV2 from this link and install

ASP.NET Core 2.2 Upgrade - IIS: limit request content length

We used to run our services on ASP.NET Core 1.1 until now. We just upgraded to ASP.NET Core 2.2, which went pretty smooth.
However, we are hosting on Azure App Service on Windows, which in turn seems to run IIS.
Now we have a custom section in the web.config to limit the max content length so when users upload files they know before actually uploading to the limit if their upload will fail:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="api/0.1/files">
<system.web>
<httpRuntime maxRequestLength="409600" executionTimeout="3600"/>
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="419430400" />
</requestFiltering>
</security>
</system.webServer>
</location>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore"
path="*"
verb="*"
modules="AspNetCoreModule"
resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="dotnet"
arguments=".\webapp.dll"
stdoutLogEnabled="false"
stdoutLogFile="\\?\%home%\LogFiles\stdout"
hostingModel="OutOfProcess"
forwardWindowsAuthToken="false"/>
</system.webServer>
</location>
</configuration>
Now, calling the route api/0.1/files (and of course all routes "beneath" files) will yield a 404 not found result with the following error message:
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
The only fix to this I could find, was to globally limit the content length:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore"
path="*"
verb="*"
modules="AspNetCoreModule"
resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="dotnet"
arguments=".\webapp.dll"
stdoutLogEnabled="false"
stdoutLogFile="\\?\%home%\LogFiles\stdout"
hostingModel="OutOfProcess"
forwardWindowsAuthToken="false"/>
<security>
<requestFiltering>
<!--400 MByte-->
<requestLimits maxAllowedContentLength="419430400" />
</requestFiltering>
</security>
</system.webServer>
</location>
</configuration>
What would be the correct way to set the limit per a specific route?
It is possible to use location to set limit for specific route.
Also, if you want to change the max request body size limit for a specific MVC action or controller, you can use the RequestSizeLimit attribute.
// GET api/values/5
[HttpGet("{id}")]
[RequestSizeLimit(40000000)]
public ActionResult<string> Get(int id)
{
return "value";
}
It sets the maximum allowed request length for this action method. You can apply this attribute at action level or controller level. This is the recommended approach to increase the limit in an ASP.NET Core MVC app.

Categories