HttpModule not called in .NET 4.5 - asp.net-mvc-4

Just spent a lot of time sifting through contradictory advice on this problem, and thought I'd post my solution.
My environment is .NET 4.5, Visual Studio 2012, working on an MVC 4 application. I created an Http Module like I'd done in the past, and added it to Web.config like so:
<configuration>
<system.web>
<httpModules>
<add name="MyModule" type="Services.MyModule, Services" />
</httpModules>
</system.web>
</configuration>
However, the application never called the module's Init(). Eventually, I found advice that the modules should instead be inside <system.webServer>, and the element named <modules> instead of <httpModules>, like so:
<configuration>
<system.webServer>
<modules>
<add name="MyModule" type="MyModule" type="Services.MyModule, Services" />
</modules>
</system.webServer>
</configuration>
Re-ran the application, and it called Init() as expected. FWIW, the page with the direction is here:
http://msdn.microsoft.com/en-us/library/ms227673.aspx
HTH

<system.web> is for IIS 6 and below (including Cassini), <system.webServer> is for IIS 7 and above. I generally put in both -- just in case -- and then add this node to <system.webServer> so it doesn't barf on the redundancy:
<validation validateIntegratedModeConfiguration="false" />

Related

Remove WebDAVModule from startup.cs asp.net core

IIS Server gives "Method Not Found Error". After Exploring Google, I got that WebDAVModule should be removed in web config file.
Every time i publish my Project, i have to add this
<modules> <remove name="WebDAVModule" /> </modules>
in Webconfig
Please suggest me how do i add this in Startup.cs or any other solution?
Just add a web.config file to your project, like bellow:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<modules>
<remove name="WebDAVModule" />
</modules>
</system.webServer>
</configuration>
You can do it in several ways
Remove from IIS model
Go to your site in IIS
Click "Modules"
Remove WebDAVModule
Restart site (might not be needed)
Remove from windows features

Cannot start website because of <handlers> in web.config

I have taken over the development of a software product that we currently deploy on an IIS server. Initially it was running with ASP.net core 2.0 but since I would like to use EF, I have configured the software to use 2.1.
The problem is, when I deploy a new version of our software, I cannot run it successfully. I tried to track down the error and i recognized that the web.config of the successfully running version and the new published version differ from each other.
Here's the version that runs just fine:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<aspNetCore processPath="dotnet" arguments=".\myProject.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
<!--ProjectGuid: 2b991c10-ec9f-493d-97b9-ee1f96458510-->
And this does not work:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\myProject.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
<!--ProjectGuid: 2b991c10-ec9f-493d-97b9-ee1f96458510-->
Obviously, it's just the handler that makes the difference. When I manually remove it, the software runs fine. How can i make sure that in future publishing processes via VB 2019, this handler is not added to the web.config? Is there any setting that I can make to prevent this error?
For ignoring the web.config during publishing, you could try <IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled> in *.csproj like
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>
<PropertyGroup>
<IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
</ItemGroup>
</Project>
For more information, you could refer web.config file
Unfortunately I cannot reconstruct that initial error message but I solved the problem in the meantime.
The problem was a <handler> tag that was added to the web.config during the publishing. We use a nested website structure with one main website and 4 sub-sites. In this configuration, the handler in the web.config must be removed according to documentation from Microsoft. My former colleague wrote a small xdt-transform script a while ago that was supposed to remove the tag when publishing the software. It always worked fine but it stopped working when I updated the SDK to 2.1. So the handler-tag was added to the web.config and that's why I could not access the website in the first place.
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document->Transform">
<system.webServer>
<handlers xdt:Transform="Remove" />
</system.webServer>
</configuration>
I figured out that the generated web.config had an additional <language>-tag before the <system.webServer>-tag. Adding the language-tag to the remove script made the script work again. Now that problem was solved and I could at least connect to the website.
But after connecting I received a HTTP Error 502.5. This was due to an old 2.0.7 version of the runtime that was installed on the server. After updating to 2.2 the website finally was rendered correctly.

.net Core API not working on IIS

I'm new to this .NET Core stuff and this is the first time I've tried to deploy one of these.
The project is an API for an Angular front end I'm building and takes HTTP requests and returns JSON. When I run it in Visual Studio on my box it is all fine. I'm running VS2017 and have .NET Core 2.0.0 installed.
I publish to a folder on the web server and it all seems to work fine, but when I try to access the API I get a 404 not found error. The server is running .NET 2.0.6 (I tried to get 2.0.0 but couldn't find it in the Hosting Bundle Installer.
If I delete the web.config the HTML file will then show up, but obviously the API doesn't work. But as the HTML file shows up there is no issue with permissions and access. There's nothing in the Event Viewer. I've also tried turning on the logging in the web.config, but it doesn't log... probably not getting far enough to.
Web config looks like this.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\RawMaterialsSystem.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
<!--ProjectGuid: f01b1621-2ced-4ad2-9ae6-004e03b0e043-->`
STEP 1: Change your web.config file to this
<?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="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
STEP 2:
In visual studio, right click the .net core app project and select "Publish"
Then publish it as a folder under bin\Release\netcoreapp2.0\publish
STEP 3:
In IIS --> Sites --> Right click on YourSite --> Under "Manage Website" select "Advanced Settings"
Make sure the "Physical Path" you are pointing to is the "publish" folder as the app directory, and not the "netcoreapp2.0" folder

ImageResizer works when testing with Visual Studio - not working on production?

I have ImageResizer installed via NuGet which is working fine when I run the ASP.Net MVC website from Visual Studio. I can get to the /resizer.debug page and it says all is well.
When I come to publish the site from Visual Studio to the main IIS instance on the same machine, ImageResizer does not work and when I browse to /resizer.debug I get a 404 Not Found error.
I have published the web.config and verified all the image resizer components are in there. Eg:
<httpModules><add name="ImageResizingModule" type="ImageResizer.InterceptModule" /></httpModules></system.web>
The ImageResizer dlls are also in the /bin directory.
However, nothing is happening and the debug page will not display.
Is there something that needs to be done to configure ImageResizer on IIS7 when publishing the project?
It appears that you only configured it for IIS Classic, not IIS7 Integrated mode. There must be a <system.webServer> element with the module installed.
From the installation guide:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="resizer" type="ImageResizer.ResizerSection,ImageResizer" requirePermission="false" />
</configSections>
<resizer>
<!-- Unless you (a) use Integrated mode, or (b) map all requests to ASP.NET,
you'll need to add .ashx to your image URLs: image.jpg.ashx?width=200&height=20 -->
<pipeline fakeExtensions=".ashx" defaultCommands="autorotate.default=true"/>
<plugins>
<add name="DiskCache" />
<!-- <add name="PrettyGifs" /> -->
<!-- <add name="SimpleFilters" /> -->
<!-- <add name="S3Reader" /> -->
</plugins>
</resizer>
<system.web>
<httpModules>
<!-- This is for IIS7/8 Classic Mode and Cassini-->
<add name="ImageResizingModule" type="ImageResizer.InterceptModule"/>
</httpModules>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<!-- This is for IIS7/8 Integrated mode -->
<add name="ImageResizingModule" type="ImageResizer.InterceptModule"/>
</modules>
</system.webServer>
</configuration>

How to publish an MVC 6 website in IIS with multiple apps in the src folder

When I try to publish an asp.net 5 website with multiple web apps in the 'src' folder. It works okay in klr but If I run it under IIS, I get this error:
Failed to resolve the following dependencies for target framework 'Asp.Net,Version=v5.0'
Here is a very basic simple project attached that you might want to run under IIS.
http://www.filedropper.com/iissampleapp
Update: updating my question as requested.
In the attached project, I just right click on "IISSampleApp" and click publish. Visual studio creates files on local file system, which I then try to run under IIS. After publish, both of the web apps reside under src folder as src\IISSampleApp and src\SubApp. The IISSampleApp is the main app that should run as website, and it just references a class DateClass from SubApp.
I have created this sample project to get the answer, my actual project have similar structure and I get the same error.
I have uploaded the Precompiled version of the project here: http://www.filedropper.com/precompilediissample
Below is my generated web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="kpm-package-path" value="..\approot\packages" />
<add key="bootstrapper-version" value="1.0.0-beta3" />
<add key="runtime-path" value="..\approot\packages" />
<add key="kre-version" value="1.0.0-beta3" />
<add key="kre-clr" value="clr" />
<add key="kre-app-base" value="..\approot\src\IISSampleApp" />
</appSettings>
</configuration>
edit the web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="kpm-package-path" value="..\approot\packages" />
<add key="bootstrapper-version" value="1.0.0-beta3" />
<add key="runtime-path" value="YOUR-RUNTIME-BASE-PATH\.k\runtimes" />
<add key="kre-version" value="1.0.0-beta3" />
<add key="kre-clr" value="clr" />
<add key="kre-app-base" value="..\approot\src\YOURPROJECT" />
</appSettings>
</configuration>
and set the security policy for \approotand \wwwroot
update: updating the answer after question's update
That just can't work like this because the kpm bundle command packages website as website and not as class library and you have 2 Startup class which is no good. If you want to share code between 2 website create a class library.