HttpContext.Current.Response.Redirect尝试将用户发送到错误的位置 [英] HttpContext.Current.Response.Redirect is trying to send users to the wrong place

查看:100
本文介绍了HttpContext.Current.Response.Redirect尝试将用户发送到错误的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段代码可以在会话超时时将用户重定向到页面:

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");
    }
}

问题是IIS找不到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.

随着时间的推移,越来越多的"/site/"级别被添加.我可以通过创建一个".../site/site/..."树并在每个树中放置一个SessionTimeout.aspx来抑制此问题,但这显然不是真正的解决方案.

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?

推荐答案

您是否尝试过使用〜?

HttpContext.Current.Response.Redirect("~/SessionTimeout.aspx");

将在运行时使用您网站的完整URL进行解析.

that will be resolved at runtime with the full url of your site.

这篇关于HttpContext.Current.Response.Redirect尝试将用户发送到错误的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆