Ответ 1
В IIS7 и выше используйте
<configuration>
<system.webServer>
<modules>
<add name="CustomModule" type="Samples.CustomModule" />
</modules>
</system.webServer>
</configuration>
У меня есть следующий модуль
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();
}
}
}
}
web.config выглядит как
<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>
Он работает на моем компьютере под управлением XP и IIS 5.1
но на моем веб-сервере, работающем с IIS7 и WS 2008, не работает, пожалуйста, помогите, я не знаю, как это сделать.
Спасибо
В IIS7 и выше используйте
<configuration>
<system.webServer>
<modules>
<add name="CustomModule" type="Samples.CustomModule" />
</modules>
</system.webServer>
</configuration>
В IIS перейдите к модулю выбора вида объектов
дважды щелкните по модулю, затем щелкните правой кнопкой мыши и нажмите (Добавить управляемый модуль)
затем введите имя и тип, как определено в web.config
Пример:
<httpModules>
<add name="CustomModule" type="WebApplication.Security.CustomModule" />
</httpModules>
Выше верно для IIS 7.5
<modules>
<add name="CustomModule" type="Samples.CustomModule" />
</modules>
Единственная проблема, с которой я столкнулся, заключается в том, что экземпляр пула приложений для конкретного приложения должен быть настроен на управляемый Pipeline = Integrated, а не Classic..
или:
Использование классического режима
Если ваше приложение использует классический режим, убедитесь, что ваше приложение настроено для этого типа пула, а ваши модули настроены в разделе system.web, а не в разделе system.webServer файла web.config.