简体   繁体   中英

ASP.NET WebForms Domain Routing

I have seen a cool implementation of ASP.NET MVC Domain Routing.
Source: http://blog.maartenballiauw.be/post/2009/05/20/ASPNET-MVC-Domain-Routing.aspx

Could this be done on ASP.NET WebForms 4.0?

Considering the fact that the Route class is not specific to MVC apps and can be easily used within the context of a plain ASP .NET WebForms project the DomainRoute class you linked to should work just fine in that context as well.

Should be an easy enough venture to prove out.

The answer to your question is yes. It's actually pretty simple. You could try the DomainRoute class or just write your own url rewriting module and be good to go. But basically you would use something like this:

http://www.gutgames.com/post/Url-Rewriting-in-ASPNet.aspx

And instead of the Path, you'd use the Url property and parse it however you want. Or you could just use an open source project like this:

http://sharedhostingsplittr.codeplex.com/

And modify it slightly if need be.

Yes add Global.ascx file in your project and add a function in it written by me

   public static void UrlRouting(RouteCollection RC, string RoutName, string routeUrl, string Page)
    {
        RC.MapPageRoute(RoutName, routeUrl, Page);
    }
after this inside Application_Start event on global.ascx file 
call that function like 
UrlRouting(RouteTable.Routes, "index", "Home", "~/index.aspx");

and then call it with route URL which is ~/Home '>Home Note: Don't forget to call ResolveUrl with your URL otherwise it cannot be called and your images and jquery,js paths should also have ResolveUrl like '/> otherwise this jquery will not work and images will not be displayed Hope this will help

The short answer is that yes, you can use routing in WebForms. Look into the System.Web.Routing namespace.

In your Application_Start in your Global.asax you can set up routes based on text or regular expressions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM