`

web..config
<system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="UrlRoutingModule"/>
      <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </modules>
    <handlers>
      <add
        name="UrlRoutingHandler"
        preCondition="integratedMode"
        verb="*" path="UrlRouting.axd"
        type="System.Web.HttpForbiddenHandler, System.Web,  
              Version=2.0.0.0, Culture=neutral,  
              PublicKeyToken=b03f5f7f11d50a3a"/>
    </handlers>

  </system.webServer>

`

Tried the following code under global.asax of application_start
RouteTable.Routes.MapPageRoute("Category", "categories/{id}", "~/JobReport/WebForm1.aspx?id=longvalue");
and under page load of the page as
Response.RedirectToRoute("Category", new { id = "1"});
But page isn't redirecting properly shown...

Dani AI

Generated

Common causes when a WebForms route exists but a redirect "doesn't work" are: the physical-file mapping contains a query string, routes are registered at the wrong time, the IIS/module entries in web.config don't match the runtime, or another handler/rewrite is winning before routing. already tried registering a route in Application_Start and calling a route redirect; 's pointer to official docs is useful background, but the checklist below targets WebForms-specific pitfalls and quick fixes.

Practical checks and fixes:

  • Map only the page path (no trailing query string) so route parameters flow via RouteData instead of being baked into the physical path.

  • Read route values from RouteData inside the page rather than relying on Request.QueryString. Example:

    protected void Page_Load(object sender, EventArgs e)
    {
        var id = Page.RouteData.Values["categoryId"] as string;
        if (!String.IsNullOrEmpty(id))
        {
            // use id (lookup, bind controls, etc.)
        }
    }
  • If generating a URL programmatically, resolve the route to a virtual path and then redirect — this avoids surprises if RedirectToRoute is not wired the same way in the hosting environment:

    var vp = RouteTable.Routes.GetVirtualPath(null,
        new RouteValueDictionary { { "categoryId", "1" } });
    
    if (vp != null)
        Response.Redirect("/" + vp.VirtualPath);

Web.config and pipeline notes:

  • For apps running on .NET 4+, the routing module is usually handled by the framework; custom module/handler entries can cause mismatches. Confirm any manual entries reference the same System.Web version the app targets and that the app pool is using the integrated pipeline if preCondition="integratedMode" is present. Also check for URL Rewrite rules or static file handlers that might intercept the friendly URL.

Quick diagnostics:

  • Type the friendly URL directly in the browser, watch the Network tab or Fiddler for the Location header, and set a breakpoint in Global.asax to verify RegisterRoutes runs exactly once on startup.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.