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

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>

Related

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>

ASP.Net Core MVC needs <environmentVariables> in web.config to work

I am publishing my ASP.Net Core 3.1 MVC project to IIS. The project includes a web api controller along with mvc controllers. It generates a web.config file as below. Once published, the app shows the page but the web api doesn't work unless I add the < environmentVariables > pointing to Development. If I put Production instead, it doesn't work.
Web.config Generated
<?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=".\MyApp.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
Web.config Modified:
<?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=".\MyApp.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
</configuration>
Modified portion of web.config
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
<environmentVariables>
Update Visual Studio to v16.6.3, which was just release (June 30). It apparently includes a fix for this issue. I just went through this similar problem, posted here:
Why do environmentVariables from launchSettings.json profiles not load when aspNetCore web.config sections exist?

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>

How to deploy an ASP NET MVC 4 Web Application using Windows Server 2008 R2 and IIS 7.5?

Firstly, I am sorry for repeat a question but its solution:
Solution
It doesn't work for me. I read the articles in this solution but I can't deploy my ASP NET MVC 4 web application. I tried this:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
...
</system.webServer>
and I tried this too:
<system.webServer>
<modules>
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
</modules>
</system.webServer>
I downloaded an update:
An update is available that enables certain IIS 7.0 or IIS 7.5 handlers
to handle requests whose URLs do not end with a period
Windows Update
but When I tried to install then
I am working on:
-Windows Server 2008 R2 Service Pack 1
-Internet Information Services 7.5
-Visual Studio 2013 Update 2 (Publish using Web Deploy)
-.Net Framework 4.5
My Modules
and finally my web.config (without the module tag because I was using both of them and I got the same result)
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<httpRuntime targetFramework="4.5" />
<compilation debug="true" targetFramework="4.5" />
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
</configuration>
When I publish my web application this is the result:
Does anyone have an idea about What am I doing wrong?
I can't deploy my MVC Web Application using one click Publish web deploy, but I deployed my Web Application using the configuration below:
I didn't need to use this tags:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
...
</system.webServer>
or
<system.webServer>
<modules>
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
</modules>
</system.webServer>

Glimpse is not logging Nhibernate queries (mvc3)

I have installed glimpse in my visual studio environment.
all working fine except nhibernate...
this is how I pass the factory:
factory = configuration.BuildSessionFactory();
NHibernate.Glimpse.Plugin.RegisterSessionFactory(factory);
this is my relevant sections in the web config:
<configuration>
<configSections>
<section name="glimpse" type="Glimpse.Core.Configuration.Section, Glimpse.Core" />
</configSections>
<appSettings>
<add key="nhibernate-logger" value="NHibernate.Glimpse.LoggerFactory, NHibernate.Glimpse" />
<add key="NHibernate.Glimpse.Loggers" value="command" />
</appSettings>
<system.web>
<!-- Glimpse: This can be commented in to add additional data to the Trace tab when using WebForms
<trace writeToDiagnosticsTrace="true" enabled="true" pageOutput="false"/> -->
<httpModules>
<add name="Glimpse" type="Glimpse.AspNet.HttpModule, Glimpse.AspNet" />
</httpModules>
<httpHandlers>
<add path="glimpse.axd" verb="GET" type="Glimpse.AspNet.HttpHandler, Glimpse.AspNet" />
</httpHandlers>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<add name="Glimpse" type="Glimpse.AspNet.HttpModule, Glimpse.AspNet" preCondition="integratedMode" />
</modules>
<handlers>
<add name="Glimpse" path="glimpse.axd" verb="GET" type="Glimpse.AspNet.HttpHandler, Glimpse.AspNet" preCondition="integratedMode" />
</handlers>
</system.webServer>
<glimpse defaultRuntimePolicy="On" endpointBaseUri="~/Glimpse.axd">
</glimpse>
</configuration>
Any idea?
Thanks
Did you install the NHibernate.Glimpse NuGet package?
The Glimpse.Ado NuGet package only adds ADO profiling when used in combination with DbProviderFactory