Click here to Skip to main content
15,886,095 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 www.mydomain.com/admin/ its redirecting me to the login page with ReturnURL parameter like this. www.mydomain.com/login.aspx?ReturnURL=%2fAdmin%2f.

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 www.mydomain.com/admin/ 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.
else
{
    FormsAuthentication.SetAuthCookie(txtCompanyEmail.Text, false);
    Response.Redirect("~/");
}
Posted

1 solution

Hi,

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.

<pre>
<authentication mode="Forms">
<forms name="yourAppName" defaultUrl="yourInternalUrlWhichIsProtected" loginUrl="login.aspx" protection="All" timeout=".." slidingExpiration="true" path="/"/>
</authentication>
</pre>
 
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