Multiple paths in handlers web.config - asp.net-core

How can I set multiple paths for aspNetCore in the handlers section of my web.config? I have tried different ways, but they result in either 500 or 404 errors:
<handlers>
<remove name="aspNetCore" />
<add name="aspNetCore" path="/api/*, /swagger/*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
and
<handlers>
<remove name="aspNetCore" />
<add name="aspNetCore" path="/api/*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
<add name="aspNetCore" path="/sawagger/*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>

For path, it did not accept /api/*, /swagger/*, and you should not define the multiple handlers with the same name aspNetCore.
Try suggestion below:
<handlers>
<add name="aspNetCore" path="*/home*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
<add name="aspNetCoreapi" path="*/api/*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
For Asp.Net Core, you should not use handler and module to control the request, try Middleware.
Check Migrate HTTP handlers and modules to ASP.NET Core middleware

Related

.NetCore Web API: I got error 403 for put and delete in hosting server

I am getting 403 error when doing PUT and DELETE but GET and POST are fine.
Here is my web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="false">
<remove name="WebDAVModule" />
</modules>
<handlers>
<remove name="WebDAV" />
<remove name="ExtensionlessUrl-Integrated-4.0" />
<add name="ExtensionlessUrl-Integrated-4.0"
path="*." verb="GET,HEAD,POST,DEBUG,DELETE,PUT"
type="System.Web.Handlers.TransferRequestHandler"
preCondition="integratedMode,runtimeVersionv4.0" />
<remove name="aspNetCore" />
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\MyApp.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
In my local machine it works fine, but not in the hosting server. I have contacted the server support. They said that they already allow the PUT and DELETE verbs from their server.
Is there anything I can do?
Try this code:-
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<modules runAllManagedModulesForAllRequests="false">
<remove name="WebDAVModule" />
</modules>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\XXXXXXXXXXX.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
UPDATE
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

appConfig Unrecognized configuration section system.webServer

Good day.
I am having trouble with setting up app.config.
The issue starts when I try to access a PayPal node from appConfig.
I ran into the following error "Unrecognized configuration section system.webServer."
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<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" />
<security>
<requestFiltering>
<!-- This will handle requests up to 100MB -->
<requestLimits maxAllowedContentLength="102400" />
</requestFiltering>
</security>
</system.webServer>
<configSections>
<section name="paypal" type="PayPal.SDKConfigHandler, PayPal" />
</configSections>
<paypal>
<settings>
<add name="mode" value="sandbox"/>
<add name="clientId" value="xxx"/>
<add name="clientSecret" value="xxx"/>
</settings>
</paypal>
</configuration>

how to set "stdout=true" while doing a webdeploy for asp.net core v3.1 app?

I am publishing an asp.net core v3.1 app in visual studio 2019
since core apps do not create a web.config
webdeploy creates it and publishes its own web.config on every publish
while it does that
it sets the stdout=false and i would like to be true -
anyone know how to control this?
i was toying around with trying to configure something in the .csproj
but never found the correct combination
heres what the published web.config looks like:
<aspNetCore processPath="dotnet" arguments=".\myproj.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
and of course heres what i want it to look like:
<aspNetCore processPath="dotnet" arguments=".\myproj.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
another post about this same issue here:
https://github.com/MicrosoftDocs/azure-docs/issues/31380
You can add a web.config to your poject by right click the project, add=>newItem=>Web=>Web Configuration File.And then you can set stdoutLogEnabled in it.
Example(pay attention you need to add hostingModel="inprocess"to web.config):
<system.webServer>
<handlers>
<remove name="aspNetCore"/>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="InProcess"/>
</system.webServer>
And here is the published web.config:
<?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=".\case1(5-26).dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>

IIS 7.5 error 405 the PUT method not supported

i have Web api WCF RESTfull Server on IIS 7.5 on windows 7 64-bit.
i am tring to update one record via PUT method, but i get error 405. i have tried allowing PUT verb in my Web.Config like this:
<system.webServer>
<modules>
<remove name="WebDAVModule" />
</modules>
<handlers>
<remove name="WebDAV" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Execute" preCondition="integratedMode,runtimeVersionv4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Execute" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Execute" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
</handlers>
....
i also disabled WebDAV as you can see, but still getting 405.
any one has a suggestion?
Try removing the webdav module manually from GUI of IIS.
1) Goto the iis.
2) Goto the respective site.
3) Open "Handler Mappings"
4) Select WebDav. Right click on it and delete it.
Note: this will also update your web.config of the web app.

How to configure IIS 7.5 for extensionless url's on castlerock monorail

I'm using Windows 7 (IIS 7.5) and have been struggling with getting it setup to use extensionless url's. This is what my web.config looks like:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<clear />
<add name="ASPX" path="*.aspx" verb="*" type="" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" allowPathInfo="false" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="4194304" />
<add name="StaticF" path="*.*" verb="FILE, GET" type="" modules="StaticFileModule" scriptProcessor="" resourceType="Unspecified" requireAccess="Script" allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="MR" path="*" verb="*" type="" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" allowPathInfo="false" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="4194304" />
</handlers>
</system.webServer>
Going to any url without an extension gives a 404 - resource cannot be found error thrown by ASP.NET. Any help would be greatly appreciated.
Assuming you do not want regular webforms you could remove the "ASPX" line
As for the mapping of "*" to MR, you need another handler factory to set in the "type" attribute:
<add name="MR" path="*" verb="*"
type="Castle.MonoRail.Framework.MonoRailHttpHandlerFactory,
Castle.MonoRail.Framework"
modules="ManagedPipelineHandler"
scriptProcessor=""
resourceType="Unspecified"
requireAccess="Script"
allowPathInfo="false"
preCondition=""
responseBufferLimit="4194304" />