HttpContext.Current.Response.Redirect 试图将用户发送到错误的位置
我有一段代码,可以在会话超时时将用户重定向到页面:
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
string szCookieHeader = HttpContext.Current.Request.Headers["Cookie"];
if ((null != szCookieHeader) && (szCookieHeader.IndexOf("ASP.NET_SessionId") >= 0))
{
HttpContext.Current.Response.Redirect("SessionTimeout.aspx");
}
}
问题是 IIS 找不到 SessionTimeout.aspx,因为它查找的位置错误:
The file '/site/site/site/site/site/site/Site/SessionTimeout.aspx' does not exist.
随着越来越多的“/site/”级别随着时间的推移不断添加。我可以通过创建“.../site/site/...”树并在每个树中放置 SessionTimeout.aspx 来抑制问题,但这显然不是真正的解决方案。
有谁知道发生了什么事吗?
I've got a section of code that redirects users to a page when their session times out:
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
string szCookieHeader = HttpContext.Current.Request.Headers["Cookie"];
if ((null != szCookieHeader) && (szCookieHeader.IndexOf("ASP.NET_SessionId") >= 0))
{
HttpContext.Current.Response.Redirect("SessionTimeout.aspx");
}
}
The problem is that IIS can't find SessionTimeout.aspx because its looking in the wrong place:
The file '/site/site/site/site/site/site/Site/SessionTimeout.aspx' does not exist.
With more and more "/site/" levels being added as time goes on. I can suppress the problem by creating a tree of ".../site/site/..." and placing an SessionTimeout.aspx in each but this is obviously not a true solution.
Does anyone know what's going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您尝试过使用 ~ 吗?
这将在运行时使用您网站的完整 url 进行解析。
Have you tried to use ~ ?
that will be resolved at runtime with the full url of your site.
您的重定向是相对于当前页面的。将 ~/ 添加到 url 以使其查看站点的根目录。
您的重定向应为:
Your redirect is relative to the current page. Add ~/ to the url to have it look at the root of the site.
Your redirect should read: