【问题标题】:Removing default.aspx from the url in ASP.NET 2005从 ASP.NET 2005 中的 url 中删除 default.aspx
【发布时间】:2011-09-27 20:29:45
【问题描述】:

我有一个在 IIS 6.0 上设置的应用程序。我们在使用 default.aspx 页面进行搜索引擎优化时遇到问题。 例如,当我输入 www.xxxxxx.com/default.aspx 时,它应该重定向到 www.xxxxxx.com。

谁能帮我解决这个问题?

【问题讨论】:

    标签: asp.net seo canonical-link


    【解决方案1】:
      public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack)
                {
                    if (HttpContext.Current.Request.RawUrl == "/default.aspx")
                    {
                        Response.StatusCode = 301;
                        Response.Status = "301 Moved Permanently";
                        Response.RedirectLocation = "/";
                        Response.End();
                    }
                }
             }
         }
    

    【讨论】:

    • HttpContext.Current.Request.RawUrl 给我 /foldername/default.aspx 无论我浏览到 /foldername 还是 /foldername/default.aspx,这样代码就会永远重定向:(
    • @JordanHudson,文件夹名称是单独的应用程序吗?
    【解决方案2】:

    在 IIS 中的 Documents 选项卡下设置默认文档。进入“文档”选项卡后,选中“启用默认内容页面”并将 Default.aspx 设置为列表中的第一项(或唯一一项)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-09
      • 2010-11-03
      • 2020-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-24
      • 2011-02-26
      相关资源
      最近更新 更多