我遇到了一个问题(asp.net 3.5):当导航到https://mypage.net时,它会将我重定向到https://mypage.net/Login.aspx?ReturnUrl=%2f不允许登录(因为ReturnUrl=%2f)。
为了解决这个问题,我更改了 global.aspx Application_BeginRequest:
protected void Application_BeginRequest(object sender, EventArgs e)
{
// redirect user from http to https
if (!Request.IsLocal && !Request.IsSecureConnection)
{
string redirectUrl = Request.Url.ToString().Replace("http:", "https:");
Response.Redirect(redirectUrl);
}
// I HAVE ADDED THESE LINES!!!!!!!!!!!!!!
if (Request.AppRelativen aCurrentExecutionFilePath == "~/")
HttpContext.Current.RewritePath("Login.aspx");
}
现在它似乎工作完美,但不是。
问题是我有另一个可以通过 https://mypage.net/QA访问的虚拟应用程序 如果我直接输入 https://mypage.net/QA/login.aspx那么一切都很好。
但是,如果我输入https://mypage.net/QA,则会显示“虚拟路径 '/Login.aspx' 映射到另一个应用程序,这是不允许的。”
- 如果我使用https://mypage.net/QA它会给我一个错误
- 如果我使用https://mypage.net/QA/它不会给我一个错误并且 Login.aspx 被加载
- 我还尝试更改 global.aspx: HttpContext.Current.RewritePath("* ~/ *Login.aspx"); 但在这种情况下,当我对https://mypage.net/qa应用程序认为我在https://mypage.net而不是虚拟应用程序 QA 时。
你如何处理这个问题?