Click here to Skip to main content
15,877,915 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Hi there is a problem in my login page.

The scenario is,

For example i go to its redirecting me to the login page with ReturnURL parameter like this.

I am logging in with admin account and everything works fine.

But if i go to Login.aspx directly which means there isn't ReturnURL QueryString field.

I log in with same admin account but when i try to go after i logged in its redirecting me back to the login page.

I'm doing navigates like this. What i am missing?
//check if there is a ReturnURL
if (QueryStringTool.IsExistAndNotNull("ReturnURL"))
    string returnUrl = Request.QueryString["ReturnURL"].ToString();
    Response.Redirect(FormsAuthentication.GetRedirectUrl(txtCompanyEmail.Text.Trim(), false));
//ReturnURL doesn't exists.
    FormsAuthentication.SetAuthCookie(txtCompanyEmail.Text, false);

1 solution


first of all, you should recheck the setting of your authcookie. That looks wrong (setting
it only if returnurl is not set ..that looks..not intended and should've happened before - right after verifying the login credentials)

Then, you dont need to check returnurl yourself. formsauthentication is handling that for
your. In your web.config, set the appropiate defaulturl and loginurl in the forms authentication section. E.g.

<authentication mode="Forms">
<forms name="yourAppName" defaultUrl="yourInternalUrlWhichIsProtected" loginUrl="login.aspx" protection="All" timeout=".." slidingExpiration="true" path="/"/>
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900