This post has been republished via RSS; it originally appeared at: IIS Support Blog articles.
As of this writing, when HTTP module is enabled, the warming HTML page defined in AppInt module may not load properly. Good news is, there is a workaround which is to place the managed module onto the GAC to have the warming page shown correctly.
FYI, for the right testing, you need to recycle IIS apppool first.
Here is how you can make a test/sample managed-module and place it in the GAC (code sample is placed at the end of this blog).
Build MyIIS7Procject.dll from the Developer Command Prompt for VS 2019
md c:\temp\dev
cd c:\temp\dev
create C:\temp\dev\testmodule.cs
sn -k mytestkey.snk
\windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /t:library /out:C:\temp\dev\MyIIS7Project.dll /debug C:\temp\dev\testmodule.cs /r:System.Web.dll /keyfile:C:\temp\dev\mytestkey.snk
gacutil /uf MyIIS7Project
gacutil /i C:\temp\dev\MyIIS7Project.dll
Get the path of MyIIS7Project in GAC
gacutil /l MyIIS7Project
C:\temp\dev>\tools\Amd64\gacutil.exe /l MyIIS7Project Microsoft (R) .NET Global Assembly Cache Utility. Version 4.0.30319.1 Copyright (c) Microsoft Corporation. All rights reserved.
The Global Assembly Cache contains the following assemblies: MyIIS7Project, Version=0.0.0.0, Culture=neutral, PublicKeyToken=63d950d99899da73, processorArchitecture=MSIL
|
Open %windir%\system32\inetsrv\config\applicationhost.config and put the below line at the bottom of existing <module> section.
<add name="TestModule" type="MyModule.TestHttpModule, MyIIS7Project, Version=0.0.0.0, Culture=neutral, PublicKeyToken=63d950d99899da73" preCondition="managedHandler,runtimeVersionv4.0" />
NOTE:
- the first part of type is from the class name in the dll file
- the second part is the path in GAC after removing “processorArchitecture=MSIL”
Code sample:
And here is the sample source code for the testmodule.cs:
/*
Content of testmodule.cs
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
namespace MyModule
{
public class TestHttpModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.BeginRequest += context_AddHeaders;
}
void context_AddHeaders(object sender, EventArgs e)
{
var httpApplication = sender as HttpApplication;
if (httpApplication != null)
{
HttpContext context = ((HttpApplication)sender).Context;
if (context.Request.ServerVariables["APP_WARMING_UP"] == "1")
{
context.Response.AddHeader("AppInitTest", "The request is called during IIS Appinit is on processing!!!");
}
else
{
context.Response.AddHeader("AppInitTest", Environment.MachineName);
}
}
}
public void Dispose()
{
}
}
}