简体   繁体   中英

hide extension of the page like .aspx

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

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

如果你谷歌重写URL ,应该有很多结果,告诉你如何将http://default.com/index.aspx?value=13转换为http://default.com/index/13

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>

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