getting swagger to run in asp.net - c#

I've inherited a class library that is using .NET Framework 4.7.2. In the library there are a bunch of ApiControllers with a number of HttpPost and HttpGet Methods on them. Errors have started occurring on some of the methods and these methods are typically called from a wordpress site.
To try and make things a bit easier for me to debug, I'm trying to install swagger into the solution. I've installed Swashbuckle.core with a runtimne version of 4.0.30319 and this has created a basic SwaggerConfig.cs file in my App_Start folder.
In the properties for the solution the project url is http://localhost/WordpressService and it's running under local IIS.
I have a local version of wordpress running in Microsoft Edge, and in IIS I can see that the WordpressService is running on port 80.
So now in the WordpressService solution I try to attach the debugger to the browser, then in the browser I try to enter http://localhost/WordpressService/swagger and other variations of the address, but all the time I receive the following error:
HTTP Error 500.21 - Internal Server Error Handler
"ExtensionlessUrlHandler-Integrated-4.0" has a bad module
"ManagedPipelineHandler" in its module list
I have this section in my web.config file:
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer> >
within IIS in the Handler Mappings section I can see ExtensionlessUrlHandler-Integrated-4.0 and it is enabled.
it also suggests that asp.net may not be installed correctly but it must be as I'm using VS 2017 and would need to be there for that. Looking around the net, the default SwaggerConfig.cs should be enough to get me going.
The only thing I can think of is that I may have installed the wrong version of swagger, but I'm not sure in that case which version I should be installing for this .NET Framework.

Ok, I figured the issue out and thought I'd post my answer for anyone else that may come across this issue. From IIS installation, it appears that only Framework 3.5 had been installed and not Framework 4.8. Installing 4.8 in the IIS section seems to have resolved this and I can now see my end points via swagger.

Related

ASP.NET Core + Framework in IIS getting HTTP 404

Ok - this is my first deployment of an ASP.NET Core app. One wrinkle to keep in mind is that I am using ASP.NET Core 2.2 and targeting Framework version 4.6.2 (not .Net Core). It all runs fine on my local machine with VS2017 and IISExpress.
I went through the procedure outlined by MS here: Host ASP.NET Core on Windows with IIS The documentation is long and complicated, but I think I covered everything. It makes one thing clear: The in-process hosting model isn't supported for ASP.NET Core apps that target the .NET Framework. So, I know I need to use Out-of-Proc.
Some other points:
I published the app to a local folder and copied it to the server without any changes.
I created the new app in the Default Web Site and gave it its own app pool - set as "No Managed Code"
Out-of-proc is the default, so I have not done any special config for this.
I have confirmed that AspNetCoreModuleV2 appears in the list of Modules.
The Result
Every page I hit I get HTTP404. I am running IE locally on the server and using a URL like: http://localhost/MyApp/Home/MyView
The application pool shows having 1 application running.
The App Event Log shows a message like: Application '/LM/W3SVC/2/ROOT/MyApp' started process '8864' successfully and process '8864' is listening on port '37706'. It shows no errors.
I have tried adding a default.htm file to the root of the app and loading the static page directly (using http://localhost/MyApp/default.htm). This gives 404. If I remove the web.config, this page will load.
I really didn't expect deploying the app to be this complicated.
Can anyone provide any guidance on how to troubleshoot or fix this problem?
Update 1: Web.config is below. I have tried with and without hostModel=... aspNetCore logs show successful startup. Nothing is added to the log with each page access attempt (seems weird)
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
-->
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
<remove name="BlockViewHandler" />
<add name="JavaScript" path="*.js" verb="GET,HEAD" type="System.Web.StaticFileHandler" />
<add name="CSS" path="*.css" verb="GET,HEAD" type="System.Web.StaticFileHandler" />
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
<aspNetCore processPath=".\My.App.Name.exe" arguments="" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="OutOfProcess">
<environmentVariables />
<handlerSettings>
<handlerSetting name="debugLevel" value="file" />
<handlerSetting name="debugFile" value="d:\Log\MyApp.log" />
</handlerSettings>
</aspNetCore>
</system.webServer>
</configuration>
<!--ProjectGuid: ee76911e-decb-48b7-bd74-36ebfbdb22b6-->
Solved! I was making use of the ASPNETCORE_ENVIRONMENT environment variable, but was unaware that the publish process does not put this in web.config. I added this to Web.config:
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
and the pages now load.
The most useful diagnostics I found were at this link Troubleshoot ASP.NET Core on IIS There they recommended that I run My.App.Name.exe from the command prompt. This creates a web process and assigns it to a port and gives you all the console output. This allowed me to figure out it was actually half working and that led me to the fact that I was missing the Env Variable.
Thanks again for the suggestions...

Error trying to host an ASP.NET 2.2 Website on Plesk Onyx 17.8.11 - HTTP Error 500.0 - ANCM In-Process Handler Load Failure

I'm attempting to host a ASP.NET 2.2 Website on a interserver.com shared hosting platform. They are using Plesk Onyx version 17.8.11 as their hosting platform control panel.
I've verified the hosting is routed and setup correctly but still get the runtime error:
HTTP Error 500.0 - ANCM In-Process Handler Load Failure
The specified version of Microsoft.NetCore.App or Microsoft.AspNetCore.App was not found
The in process request handler, Microsoft.AspNetCore.Server.IIS, was not referenced in the application
ANCM could not find dotnet.
I reported the issue to customer service and they have sent me a few articles of things to try but no solution has been found. Since the error says that the key aspnet core library could not be found, they said they have "installed .NET core 2.1.10 and 2.2.2 hosting bundle" but I'm still getting the same error.
The web.config on the host (auto-generated) is:
<?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=".\BridgeSite.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: 7bcb9c33-cd6b-4078-9742-869d5dd7bxxx -->
Any suggestions stackoverflow family?
Since this is a shared hosting platform I do not have access to fiddle around with server configurations. From what I can tell, something went wrong with the ASP.NET Core 2.2.4 runtime installation and AspNetCoreModuleV2.dll is missing/corrupt/misplaced?
After spending far to much time on this I found a couple workarounds:
Every time you publish, go to the folder on the host where the code was published, open the auto-generated web.config, under the handlers node replace "AspNetCoreModuleV2" with "AspNetCoreModule". This works, by defaulting it back to the previous package, but is crappy because it has to be done manually every time the code is published.
OR,
in the Visual Studio solution, open (or create new) publish profile under Properties > PublishProfiles. In the PropertyGroup add: <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>. This works but is a big hack and the application will not have all the performance gains of being InProcess (Default)
After testing, I found you can use one or the other, you don't have to use both.
I'm hoping this issue will resolve itself over time as the hosting service continues to update their runtimes, but for now hopefully those workarounds will help you too.
This error is documented, along with the solution:
500.0 In-Process Handler Load Failure
The worker process fails. The app doesn't start.
The ASP.NET Core Module fails to find the .NET Core CLR and find the in-process request handler (aspnetcorev2_inprocess.dll). Check that:
The app targets either the Microsoft.AspNetCore.Server.IIS NuGet package or the Microsoft.AspNetCore.App metapackage.
The version of the ASP.NET Core shared framework that the app targets is installed on the target machine.
The most likely scenario is that you've failed to installed the .NET Core runtime at all or at least failed to install the correct version thereof to match what your project is targeting.
For Asp.Net Core 2.2 MVC.
1. Create web.config at the root on the Project.
2. Past this configuration:
<?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=".\MyApp.dll"
stdoutLogEnabled="false"
stdoutLogFile=".\logs\stdout"
hostingModel="InProcess" />
</system.webServer>
</location>
</configuration>
I was having the same issue with Interserver.com.
Support was able to solve the problem by switching my application pool to 64 bit. From what I have read in regards to other Plesk hosting providers is that by default the scripts that create your virtual machine by default create the application pool in 32 bit. I'm guessing that AspNetCoreModuleV2 requires 64 bit, but that is just a guess. Happy that my site is running in process now.

Why does Asp.Net Core 2.1 WebApi return a 500.19 error?

I have a small webapi service, which works under Visual Studio but doesn't work under IIS.
I did the next:
New application was added to the default web-site in IIS console.
Application was published into app folder from VS via File System
(Framework-dependent and Portable options were selected).
When I try access folder with my app (like http://localhost/example/) I receive 500.19 error with code 0x8007000d. I read this error can happen if ApplicationHost.config or Web.config has wrong XML options. I use default Web.config file (ApplicationHost.config is not used by me) which VS generate, and I don't understand what can be bad in it. Here's my Web.config file:
<?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=".\Service.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</location>
</configuration>
Lex Li wrote an excellent article: https://blog.lextudio.com/the-horrible-story-of-publishing-net-core-web-apps-for-beginners-6121662dd8c4, which described issues with publishing .NET Core Web Apps.
In my case, I hadn't installed the ASP.NET Core Hosting Bundle. A simple solution which is hard to be found because it is difficult to understand what should be searched for.
I ran into the exact same issue and in addition to the marked correct answer, this is what worked for me:
I installed the ASP.NET Core Hosting Bundle and was still receiving the same error.
Repairing the installation resolved my issue.
Programs and Features -> Repair "Windows Server Hosting"
"If the Hosting Bundle is installed before IIS, the bundle installation must be repaired. Run the Hosting Bundle installer again after installing IIS.
If the Hosting Bundle is installed after installing the 64-bit (x64) version of .NET Core, SDKs might appear to be missing (No .NET Core SDKs were detected). To resolve the problem, see Troubleshoot ASP.NET Core projects." - Install the .NET Core Hosting Bundle

.net core application error 502.5 if run as virtual directory in IIS

I am having problem configuring .net core application to work as virtual directory in iis.
If i start .net core application directly with its port it works fine.
I am getting 502.5 response and in event viewer there is this message
Application 'MACHINE/WEBROOT/APPHOST/DEFAULT WEB SITE' with physical root 'C:\inetpub\wwwroot\' failed to start process with commandline ' ', ErrorCode = '0x80070057 : 0.
I have removed parent handlers in .net web.config like this
<handlers>
<remove name="httpPlatformHandler"/>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
</handlers>
In order to run an ASP.NET Core application make sure you:
Have the ASP.NET Core Web Hosting Bundle (required for a server!)
Publish your application - should include a web.config
Deploy the Publish output to your server
Set up an Application Pool
Set .NET Framework to none (optional but usually a good idea)
Use an account that has read permissions in the virtual folder
The hosting bundle includes the ASP.NET Core Module for IIS which allows IIS to launch. Without ASP.NET Core apps will not run on IIS.
You also need to publish your application, which produces a final output folder that contains your binaries and config files including a web.config in the root and a wwwroot root folder with your content. To test you should make sure you can run your app from the command line with:
dotnet yourMainAssembly.dll -c Release
If this doesn't work fix this first as this is essentially what IIS fires. once the standalone works you can try using IIS.
ASP.NET Core projects created in Visual Studio automatically include a web.config and that should have everything you need to run under IIS. For a basic setup that should be all you need. The generated web.config should take care of getting your app running.
If you're using a virtual you might have an issue with the parent side configuration bleeding into your virtual because virtuals inherit settings from the parent. If that's the case either choose the same version of .NET Framework for your application pool, or share the application pool with the parent. Alternately you can use <clear /> in the <handlers> section to clear out any handlers from up the hierarchy.
<configuration>
<system.webServer>
<handlers>
<clear>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" startupTimeLimit="3600" requestTimeout="23:00:00">
<environmentVariables />
</aspNetCore>
</system.webServer>
</configuration>
I have a blog post with a lot more details on hosting on IIS along with some additional configuration for static files here:
Publishing and Running ASP.NET Core Apps under IIS
IIS Rewrite Rules and Static File Configuration for ASP.NET Core

Deploying MVC4 .net 4.5 website to IIS7 Forbidden 403

I am trying to deploy a website to an IIS webserver but I keep getting a 403 forbidden error. I have tried all the solutions on this question but to no avail so I was wondering what else could be causing the 403
When I publish a different site to the same folder with the same app pool it will run and the only difference between the 2 sites is the one that isn't working is .net 4.5 and the one that is is .net 4
Has anyone got any ideas what may be causing the site to throw a 403 - I have checked the event viewer and nothing seems to be showing up
After trying and failing with a lot of things, I have found that it was due to the routing with MVC and adding the following line into my web config seems to have fixed it:
<modules runAllManagedModulesForAllRequests="true"></modules>
Put this in your web.config file:
<system.webServer>
<modules>
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
</modules>
Also copy to the bin folder on IIS any missing DLLs it complains about (like. System.Web.Http). Set them to copylocal=true in VS to prevent this error in future.
The other anwswer to this question (
<modules runAllManagedModulesForAllRequests="true"></modules>
) runs all modules all the time. According to this blog it's too drastic and will lead to errors and slow speeds: http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html

Categories