【问题标题】:How to remove/hide the default page (default.aspx or index.aspx) from the domain name URL with ASP.NET 3.5如何使用 ASP.NET 3.5 从域名 URL 中删除/隐藏默认页面(default.aspx 或 index.aspx)
【发布时间】:2023-03-09 21:12:01
【问题描述】:

我的要求是我们的 SEO 专家建议 www.example.com/index.aspx
应加载为 www.example.com 以用于 google index Canonical Issue

我还想提一下,因为共享服务器我们无法访问 IIS 服务器,并且支持人员不太合作。

我尝试了 global.asax 中的以下代码。 Index.aspx 是该站点的默认页面,因此它会引发错误:“500 - 内部服务器错误。”

void Application_BeginRequest(object sender, EventArgs e)
{

    HttpContext incoming = HttpContext.Current;

    string oldpath = incoming.Request.Url.AbsoluteUri.ToLower();
    if (oldpath.Contains("index.aspx") == true)
    {
    HttpContext.Current.RewritePath("http://www.example.com", false);
    }
}

//Also tried following 
void Application_BeginRequest(object sender, EventArgs e)
{

    HttpContext incoming = HttpContext.Current;

    string oldpath = incoming.Request.Url.AbsoluteUri.ToLower();
    if (oldpath.Contains("index.aspx") == true)
    {
        Response.Redirect"http://www.example.com"
    }
}

【问题讨论】:

    标签: url-rewriting global-asax rewritepath


    【解决方案1】:

    你可能想用

    包装它
    <script language="c#" runat="server">
    </script>
    

    【讨论】:

      猜你喜欢
      • 2021-08-07
      • 1970-01-01
      • 2010-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-24
      • 2020-10-13
      相关资源
      最近更新 更多