Need help for routing in asp.net webform
i want to achieve few redirection like
when user will type this www.mysite.com/label/uk
or www.mysite.com/label.aspx/uk
then my labeluk.aspx will load or
when user will type this www.mysite.com/label/us
or www.mysite.com/label.aspx/us
then my labelus.aspx will load or
whe开发者_高级运维n user will type this www.mysite.com/label/fr
or www.mysite.com/label.aspx/fr
then my labelfr.aspx will load.
so please tell me how do i define pattern for routing like
RouteTable.Routes.MapPageRoute("Source1", "label/{ID}", "~/labeluk.aspx");
RouteTable.Routes.MapPageRoute("Source1", "label/{ID}", "~/labelus.aspx");
i am not being able to figure out how to achieve it by routing. please help me to form the maproute. thanks
You can look into URL Rewriting on the web or SEO Urls
http://www.codeproject.com/KB/aspnet/URL-Rewriting-in-ASPNET.aspx
you could do something like this..
keep one route (in Global) as
RouteTable.Routes.MapPageRoute("Source", "label/{ID}, "~/label.aspx");
so all will resolve /label.aspx, then on label.aspx check ID param e.g.
Page.RouteData.Values.ContainsKey("ID")
and depending on whether it's uk, fr or us do
HttpContext.Current.RewritePath("/labeluk.aspx", false);
alternatively not even need to have /label.aspx just check ID param in Global and do RewritePath there
精彩评论