Reputation: 565
I have a path say "http://default.com/index.aspx" here i can see page "index.aspx" page content but I donot want to show ".aspx" extension on my browser url. I can do this while making a folder name as "index" and putting my index.aspx page in that folder and just making write url as "http://default.com/index/"
But is there another simple and good way to do soo?.I am using asp.net 4.0
Upvotes: 0
Views: 2565
Reputation: 596
As you're using asp.net 4.0, then you can use the NuGet Package Manager to add the 'Microsoft.AspNet.FriendlyUrls' library. It look like this:
Install the first one (will also install the next one automaticlly). After the install completed, it add a cs file name 'RouteConfig.cs' under the App_Start folder; the file's code like below:
public static class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
var settings = new FriendlyUrlSettings();
settings.AutoRedirectMode = RedirectMode.Permanent;
routes.EnableFriendlyUrls(settings);
}
}
To enable the friendly url , you need to add the below code to the global.asax
void Application_Start(object sender, EventArgs e)
{
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
http://msdn.microsoft.com/en-us/library/jj891072(v=vs.100).aspx
Upvotes: 1
Reputation: 2113
I have been using UrlRwrting.net for years, works good.
With that DDL, all you need to add in your webconfig is something like this:
<urlrewritingnet defaultProvider="RegEx" xmlns="http://www.urlrewriting.net/schemas/config/2006/07">
<rewrites>
<add name="rule1" virtualUrl="^~/(.*)/" destinationUrl="~/$1.aspx" ignoreCase="true"/>
<add name="rule2" virtualUrl="^~/(.*)" destinationUrl="~/$1.aspx" ignoreCase="true"/>
</rewrites>
</urlrewritingnet>
Upvotes: 0
Reputation: 56727
If you google for URL rewriting there should be many results that show you how to turn http://default.com/index.aspx?value=13
into http://default.com/index/13
.
Upvotes: 0