views:

28

answers:

2

Greetings,

I am using Visual Studio 2010 and ASP.NET 4.0 to build a WebForms project that uses the new routing features in System.Web.Routing. When I build my solution and run it from within VS.NET's debugging environment only routes with RouteUrl's that include a ".aspx" extension are being properly routed to the PhysicalFile. It appears requests made to other URLs are not being "detected" by the routing engine for processing. In the case below, "Scenario1" shows a 404 and "Scenario2" works properly.

I would greatly appreciate any guidance you can provide.

Here is the relevant code in my global.asax:

void Application_Start(object sender, EventArgs e)
{
    // Code that runs on application startup

    // Register Routes
    RegisterRoutes();
}

void RegisterRoutes()
{
    System.Web.Routing.RouteTable.Routes.MapPageRoute("Scenario1", "scenario1/{option1}", "~/About.aspx");  
    System.Web.Routing.RouteTable.Routes.MapPageRoute("Scenario2", "scenario2.aspx", "~/About.aspx");
}

Thank you kindly for your time.

MomentSurfer

A: 

are you saying that if you type in http://mywebsite/scenario1/bob then you get the 404 or are trying to do through code? If through code, Are you properly setting the {option1} parameter

Page.GetRouteUrl("Scenario1", New With {Key .option1 = "bob"}
Lareau
Thanks for your response. A 404 is shown when I visit the address directly and when I generate the URL from code.
MomentSurfer
A: 

I found the issue to my problem after reading this post:

http://stackoverflow.com/questions/1337029/asp-net-system-web-routing-wont-route-url-unless-aspx-in-on-the-end/4061655#4061655

My VS2010 solution contains several projects: web, business layer classes, data access layer classes, etc. My web project was called "SystemName.WebForms". The period in the web project name interferes with ASP.NET 4.0's WebForm's routing for some strange reason. Once I renamed my project to "SystemName_WebForms" all of the routes work correctly.

WITH A PERIOD IN THE WEB PROJECT NAME:

  • only "scenario2" and "scenario4" work

WITHOUT A PERIOD IN THE WEB PROJECT NAME:

  • all scenarios work

ROUTES:

    RouteTable.Routes.MapPageRoute("scenario1", "scenario1/{option1}", "~/About.aspx");
    RouteTable.Routes.MapPageRoute("scenario2", "scenario2.aspx", "~/About.aspx");
    RouteTable.Routes.MapPageRoute("scenario3", "scenario3", "~/About.aspx");
    RouteTable.Routes.MapPageRoute("scenario4", "scenario4.xxx", "~/About.aspx");

Many thanks to @vincentw56 for finding and posting the answer to his question!!

MomentSurfer

MomentSurfer