Using Routing in Asp.Net Webform Application

669 Views Asked by At

I am using System.Web.Routing in the Asp.Net Webform Application. I wrote the following route in the global.asax

routes.RouteExistingFiles = true; // I made true/false both, but none works

routes.Add("competition", new Route
            (
               "Test",
               new CustomRouteHandler("~/Test/WebForm1.aspx")
            ));

And the directory structure is the following:-

Application

|

|--- Test (Folder)

   |--- Webform1.aspx

When I write in the browser http://localhost:xxxx/Test/ (using Casini), the request is handle in the traditional manner not through the routes, and, it gives me the "Directory Listing -- /test/" page.

Could you please help me out?

2

There are 2 best solutions below

2
On BEST ANSWER

I had the same problem, and I chose the pragmatic solution that the file that should handle the default path is called Default.aspx

routes.Add("competition", new Route ( "Test", new CustomRouteHandler("~/Test/Default.aspx") ));
3
On

Are you using Routing straight out the box for WebForms, I have just implemented this for "WebForms" specifically, since there is some things to be aware of:

http://haacked.com/archive/2008/03/11/using-routing-with-webforms.aspx

HTH

Update:

Using the implementation in the link still produces the same error, since the actual folder exists.

I would think that since the folder exists, it would be served (in some cases listing the folder contents may be desired)

Maybe taking a different approach would be better for instance, if the pages all point to specific extranet login pages maybe an extra descriptive folder would work, eg: /Extranets/Test/ ?