17

I have the following module

public class LowerCaseRequest : IHttpModule {
     public void Init(HttpApplication context) {
         context.BeginRequest += new EventHandler(this.OnBeginRequest);
     }

     public void Dispose() { }

     public void OnBeginRequest(Object s, EventArgs e) {
         HttpApplication app = (HttpApplication)s;

         if (app.Context.Request.Url.ToString().ToLower().EndsWith(".aspx")) {
             if (app.Context.Request.Url.ToString() != app.Context.Request.Url.ToString().ToLower()) {
                 HttpResponse response = app.Context.Response;

                 response.StatusCode = (int)HttpStatusCode.MovedPermanently;
                 response.Status = "301 Moved Permanently";
                 response.RedirectLocation = app.Context.Request.Url.ToString().ToLower();
                 response.SuppressContent = true;
                 response.End();
             }
             if (!app.Context.Request.Url.ToString().StartsWith(@"http://zeeprico.com")) {
                 HttpResponse response = app.Context.Response;

                 response.StatusCode = (int)HttpStatusCode.MovedPermanently;
                 response.Status = "301 Moved Permanently";
                 response.RedirectLocation = app.Context.Request.Url.ToString().ToLower().Replace(@"http://zeeprico.com", @"http://www.zeeprico.com");
                 response.SuppressContent = true;
                 response.End();
             }
         }
     }
}

the web.config looks like

<system.web>
  <httpModules>
      <remove name="WindowsAuthentication" />
      <remove name="PassportAuthentication" />
      <remove name="AnonymousIdentification" />
      <remove name="UrlAuthorization" />
      <remove name="FileAuthorization" />
      <add name="LowerCaseRequest" type="LowerCaseRequest" />
      <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" />
      <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</httpModules>
</system.web>

It works grate on my PC running XP and IIS 5.1

but on my webserver running IIS7 and WS 2008 dosn't works, please help I don't know how to work this out.

Thanks

Yuck
  • 49,664
  • 13
  • 105
  • 135
roncansan
  • 2,310
  • 6
  • 27
  • 34

3 Answers3

39

On IIS7 and higher use

<configuration>
  <system.webServer>
    <modules>
      <add name="CustomModule" type="Samples.CustomModule" />
    </modules>
  </system.webServer>
</configuration>
Maxime Rouiller
  • 13,614
  • 9
  • 57
  • 107
Ben Robinson
  • 21,601
  • 5
  • 62
  • 79
  • Thanks, I actually have to ahve on both ways since my developing enviroment is iis5.0 and my live enviroment is iis7 – roncansan May 29 '10 at 16:02
1

Above is correct for IIS 7.5

<modules>
  <add name="CustomModule" type="Samples.CustomModule" />
</modules>

the only problem I got, is that instance of application pool for particular application should be set to managed Pipeline = Integrated, not Classic..
or: Using Classic Mode

If your application is to use Classic mode, then make sure that your application is configured for that type of pool and your modules are configured in system.web section and not in system.webServer section of web.config file.

algor
  • 51
  • 3
  • This is a more complete answer. I had same web.config values as in the accepted answer, except that the app is running in Classic Mode. – Marc Lopez May 04 '20 at 18:04
-2

In IIS go to feature view select module

double click to module then right click and press (Add Managed Module)

then put name and type as defined in web.config

example:

<httpModules>
  <add name="CustomModule" type="WebApplication.Security.CustomModule" />
</httpModules>
EekTheCat
  • 127
  • 11
Rissa
  • 191
  • 1
  • 8