重定向 Global.asax 无效
Redirect on Global.asax not working
我的网站是空的 index.html
文件(只有强制性的 HTML 标签)。并想尝试通过 Global.asax
文件进行重定向,但是 Global.asax
文件由于某种原因无法正常工作,或者我的重定向编码错误。这是 Global.asax
上的代码:
namespace redirectURL
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
}
protected void Session_Start(object sender, EventArgs e)
{
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
string responseURL = "http://live.com/blog";
if (Request.Url.ToString().ToLower().Contains("://loc.test.com"))
{
Response.Redirect(responseURL);
}
}
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
}
protected void Application_Error(object sender, EventArgs e)
{
}
protected void Session_End(object sender, EventArgs e)
{
}
protected void Application_End(object sender, EventArgs e)
{
}
}
}
感谢转发帮助
我没有创建空白(空 Web 应用程序)网站,而是使用 "web forms application" 并将与上面相同的代码添加到我的 global.asax 文件并删除了我不需要的所有内容文件(留下 global.asax、web.config、引用和属性)。最终结果是根据需要 - 空项目,仅在 global.asax 文件上重定向。
我的网站是空的 index.html
文件(只有强制性的 HTML 标签)。并想尝试通过 Global.asax
文件进行重定向,但是 Global.asax
文件由于某种原因无法正常工作,或者我的重定向编码错误。这是 Global.asax
上的代码:
namespace redirectURL
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
}
protected void Session_Start(object sender, EventArgs e)
{
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
string responseURL = "http://live.com/blog";
if (Request.Url.ToString().ToLower().Contains("://loc.test.com"))
{
Response.Redirect(responseURL);
}
}
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
}
protected void Application_Error(object sender, EventArgs e)
{
}
protected void Session_End(object sender, EventArgs e)
{
}
protected void Application_End(object sender, EventArgs e)
{
}
}
}
感谢转发帮助
我没有创建空白(空 Web 应用程序)网站,而是使用 "web forms application" 并将与上面相同的代码添加到我的 global.asax 文件并删除了我不需要的所有内容文件(留下 global.asax、web.config、引用和属性)。最终结果是根据需要 - 空项目,仅在 global.asax 文件上重定向。