在Global.asax.cs文件中,使用Application_BeginRequest事件来避免无限循环。以下是代码示例:
protected void Application_BeginRequest(object sender, EventArgs e)
{
string path = Request.Path.ToLower();
if (path.Equals("/default.aspx"))
{
Response.RedirectPermanent("/home.aspx");
}
}
在上述示例中,我们使用了Application_BeginRequest事件来截取请求,再使用Response.RedirectPermanent永久重定向将请求重定向到所需页面。同时,在此事件中,我们可以添加其他逻辑,以根据需要重定向请求至不同页面,而避免无限循环。