【问题标题】:hide extension of the page like .aspx隐藏页面的扩展名,例如 .aspx
【发布时间】:2013-09-30 07:15:36
【问题描述】:

我有一条路径说 "http://default.com/index.aspx" 在这里我可以看到页面 "index.aspx" 页面内容,但我不想显示 ".aspx" 扩展名在我的浏览器网址上。 我可以这样做,同时将文件夹名称设为“index”并将我的 index.aspx 页面放在该文件夹中,并将写入 url 设为 "http://default.com/index/"

但是还有另一种简单而好的方法吗?我正在使用 asp.net 4.0

【问题讨论】:

  • 你可以用谷歌搜索“URL重写”。
  • 只是一个问题,为什么不使用已经开箱即用的 MVC?
  • @user65439 我不知道 MVC soo。

标签: c# asp.net


【解决方案1】:

当您使用 asp.net 4.0 时,您可以使用 NuGet 包管理器添加“Microsoft.AspNet.FriendlyUrls”库。看起来像这样:

安装第一个(也将自动安装下一个)。安装完成后,在App_Start文件夹下添加一个cs文件名'RouteConfig.cs';文件代码如下:

public static class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        var settings = new FriendlyUrlSettings();
        settings.AutoRedirectMode = RedirectMode.Permanent;
        routes.EnableFriendlyUrls(settings);
    }
}

要启用友好的 url,您需要将以下代码添加到 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

【讨论】:

    【解决方案2】:

    如果你用谷歌搜索URL 重写,应该会有很多结果告诉你如何将http://default.com/index.aspx?value=13 变成http://default.com/index/13

    【讨论】:

      【解决方案3】:

      我多年来一直在使用UrlRwrting.net,效果很好。

      使用该 DDL,您只需在 webconfig 中添加如下内容:

      <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>
      

      【讨论】:

        猜你喜欢
        • 2017-09-24
        • 2010-12-18
        • 2011-05-06
        • 2011-01-08
        • 1970-01-01
        • 2010-09-18
        • 1970-01-01
        相关资源
        最近更新 更多