从请求中删除default.aspx
我正在尝试从任何可能包含 default.aspx 的请求中删除它。
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext context = HttpContext.Current;
string url = context.Request.Url.ToString();
// remove default.aspx
if (url.EndsWith("/default.aspx", StringComparison.OrdinalIgnoreCase))
{
url = url.Substring(0, url.Length - 12);
context.Response.Redirect(url);
}
}
出现错误:
**too many redirects occurred trying to open...**
我可以更改什么才能使其正常工作?
谢谢
i am trying to remove default.aspx from any request that might have it.
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext context = HttpContext.Current;
string url = context.Request.Url.ToString();
// remove default.aspx
if (url.EndsWith("/default.aspx", StringComparison.OrdinalIgnoreCase))
{
url = url.Substring(0, url.Length - 12);
context.Response.Redirect(url);
}
}
gives an error:
**too many redirects occurred trying to open...**
what can i change to make it work?
thnx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
k明白了。
而不是使用:
我尝试了:
并且有效!与你们所说的一起:)
k got it.
instead of using:
i tried:
and that WORKS! together with what you guys said :)
我认为,如果您将重定向放在 if 中,则不必处理无限重定向。
I think that if you put the redirect inside the if you don't have to deal with infinite redirects.
你无休止地重定向。
每次执行以下行时,都会再次触发 Application_BeginRequest 事件。
将重定向放入 if 语句中,如下所示。
You are endlessly redirecting.
Each time the following line executes the Application_BeginRequest event is fired again.
Put the redirect inside the if statement like this.