I have a login.aspx. In which there is a code for redirecting page.
Server.Transfer(string.Format("~/admin/FillUserExtraInfo.aspx?UserName={0}",Server.UrlEncode(loginInitial.UserName)));
It did work, then in FillUserExtraInfo.aspx
protected void Page_Load(object sender, EventArgs e)
{
// retrieve the username from the querystring
userName = this.Request.QueryString["UserName"];
string mode = UsefulFunctions.GetOperatingMode();
if (mode == ConfigurationSettingValues.OperatingModes.Backup.ToString())
FormsAuthentication.RedirectToLoginPage();
However FormsAuthentication.RedirectToLoginPage() doesn’t work. The program keeps executing forward until to the end of Page_Load then goes back to login eventually.
UPDATED: During the period, I found the url bacomes http://localhost:53906/Login.aspx?ReturnUrl=%2fLogin.aspx%3fAction%3dLogout
Finally. but I got an error:
Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.
My web.config:
<authentication mode="Forms">
<forms loginUrl="Login.aspx" protection="All" timeout="30" requireSSL="false" slidingExpiration="true" defaultUrl="default.aspx" cookieless="UseDeviceProfile" enableCrossAppRedirects="false"/>
</authentication>
My questions:
- Why FormsAuthentication.RedirectToLoginPage() doesn’t work?
- How to deal with the error I encountered?
Thank you.
Second update: I added Response.End() after FormsAuthentication.RedirectToLoginPage() then it works but the exception is still there.
try using Response.Redirect(“url”, false) rather than Server.Transfer().
reference