问题
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?
回答1:
Have you tried to use ~ ?
HttpContext.Current.Response.Redirect("~/SessionTimeout.aspx");
that will be resolved at runtime with the full url of your site.
回答2:
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:
HttpContext.Current.Response.Redirect("~/SessionTimeout.aspx");
来源:https://stackoverflow.com/questions/5980037/httpcontext-current-response-redirect-is-trying-to-send-users-to-the-wrong-place