Url Rewriting in Asp.net

Posted by Alok under ASP.NET on 9/24/2012 | Points: 10 | Views : 1265 | Status : [Member] | Replies : 2
Hi,
i want solution to rewrite my url

from

http://mysite.com/8

to

http://mysite.com/default.aspx?id=8



Please note i want to type slash just after my domain name

as http://mysite.com/8
not as http://mysite.com/main.aspx/8

Thanks & Regards,
Alokssm



Responses

Posted by: Navadeebans on: 9/24/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
If I understood correctly, implement the Routing logic with Global.asax

this ll be coming under ..Application_Start
RegisterRoutes(RouteTable.Routes);
------------
public static void RegisterRoutes(RouteCollection routes)
{
routes.Ignore("{*allaspx}", new { allaspx = @".*\.aspx(/.*)?" }); //this ll ignore all aspx other than the default page
routes.Ignore("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" }); //this ll ignore the fav icon part
routes.Ignore("{*allaxd}", new { allaxd = @".*\.axd(/.*)?" }); //ignore axd files.
routes.MapPageRoute("Routing", "{Id}", "~/Default.aspx");
}
-----------------------
and finally, you must configure the web config file like below.

<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>
----------------
I hope the above content will helps to get u r logic.
Regards,
NavaDeeban S.

Alok, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Alok on: 9/27/2012 [Member] Starter | Points: 25

Up
0
Down
can i use this code in .net 3.5

Thanks & Regards,
Alokssm

Alok, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response