Configure IIS 7 and ASP.NET to route URLs

This is not an MVC theme. I have an ASP.NET application that does URL routing in a method Application_Start.

Routing looks like this:

RouteTable.Routes.Add(new Route(
  "Profile/{query}",
  new RouteValueDictionary() { {"query",string.Empty} },
  new GenericRouteHandler("~/ProfileHttpHandler.ashx")
));

A GenericRouteHandlerlooks like GetHttpHandlerusing:

var page= (IHttpHandler)BuildManager.CreateInstanceFromVirtualPath(_virtualPath, typeof(IHttpHandler));
...
return page;

And ProfileHttpHandler.ashx is just a Visual Studio template. It sets the Content-type to "text / plain" and writes "hello world".

This application works correctly when debugging in Visual Studio (on the ASP.NET development server). A GET http://localhost:59474/Profile/abc123goes to the http handler as expected.

, IIS 7 Integrated Pipeline, . HTTP 500 , , Default.aspx.

Web.Config :

<system.web>
  <httpModules>
    <add name="RoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  </httpModules>
</system.web>
<system.webServer>
  <modules runAllManagedModulesForAllRequests="true">
    <add name="RoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  </modules>
</system.webServer>

; , . - , , . :

  • mydomain.ca/routeapp: (domain.ca\wwwroot\routeapp)
  • : .
  • Windows: .
  • : .
  • ASP: .
  • ASP.NET: 2.0 Integrated Pipeline.
  • PHP: .
  • Perl: .
+3
2

web.config

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
</system.webServer>

iis.

+2

- ASP.NET - , System.Web.Routing. SP1 .NET Framework 3.5 , " ".

+1

Source: https://habr.com/ru/post/1731966/


All Articles