【问题标题】:302 Redirect all pages to homepage - ASP.NET302 将所有页面重定向到主页 - ASP.NET
【发布时间】:2013-08-17 14:20:51
【问题描述】:

有没有一种使用 ASP.NET 的方法可以 302(临时)将网站上的所有页面重定向到主页(显然不重定向主页)?

【问题讨论】:

    标签: asp.net redirect response.redirect http-status-code-302


    【解决方案1】:

    将此添加到您的 Global.asax 文件中:

    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        if (Request.Url.LocalPath != "/Home.aspx")
            HttpContext.Current.Response.Redirect("Home.aspx");
    }
    

    来自HttpResponse.Redirect Method (String) 文章:

    ASP.NET 通过返回 302 HTTP 状态码来执行重定向。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-28
      • 1970-01-01
      • 1970-01-01
      • 2017-05-29
      • 2016-11-08
      • 1970-01-01
      • 2017-01-15
      相关资源
      最近更新 更多