Using FormsAuthentication - how to override default referral

P

Phil Certain

Hi

I'm building a site that has publicly available pages and password
protected pages. Publicly available pages reside in:

/public

and password protected pages reside in:

/private

I'm using FormsAuthentication to protect the pages in /private. I've
created a login page (login.aspx) which resides in /public. When trying
to access a page in /private, the browser is referred back to
/public/login.aspx, where the user is authenticated and sent back to
the referring page in /private. Great, it all works....BUT... when a
user goes directly to /public/login.aspx and authenticates, they are
referred to /public/Default.aspx. Dang! Well, fair enough, I'm using:

FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, False)

and if there is no referring URL then it has to use a default.

What I want to happen, is when there is no referring URL, the user
should be forwarded to say, /private/profile.aspx.
Does anyone know a way of overriding the default?

Thanks in advance.
 
S

Stuart A Hill

Hi Phil,

This is the way that forms authentication works unfortunately.

One way to get around it is if there is no ReturnUrl passed in the
query string to the login page to have a default.aspx and redirect from that
page to
/private/profile.aspx.

I do not know of any other way of overriding this behaviour in forms
authentication.

Regards,

Stuart A Hill
MCSD, MCT
 
W

William F. Robertson, Jr.

You will have to work around this problem as "default.aspx" is hardcoded
into the GetRedirectUrl method.

Here is some pseudo code for this RedirectFromLoginPaeg method method
RedirectFromLoginPage(...)
{
FormsAuthentication.SetAuthCookie(...)
Response.Redirect( FormsAuthentication.GetRedirectUrl( ... ) )
}

btnLogin_Click(..)

FormsAuthentication.SetAuthCookie();
string url = Request.Querystring["ReturnUrl"];
if ( url == null )
Response.Redirect( "/private/profile.aspx", true );
else
Response.Redirect( url, true );

bill
 
P

Phil Certain

Hi William,

Many thanks for this - it works exactly as required.

Phil

You will have to work around this problem as "default.aspx" is hardcoded
into the GetRedirectUrl method.

Here is some pseudo code for this RedirectFromLoginPaeg method method
RedirectFromLoginPage(...)
{
FormsAuthentication.SetAuthCookie(...)
Response.Redirect( FormsAuthentication.GetRedirectUrl( ... ) )
}

btnLogin_Click(..)

FormsAuthentication.SetAuthCookie();
string url = Request.Querystring["ReturnUrl"];
if ( url == null )
Response.Redirect( "/private/profile.aspx", true );
else
Response.Redirect( url, true );

bill

Phil Certain said:
Hi

I'm building a site that has publicly available pages and password
protected pages. Publicly available pages reside in:

/public

and password protected pages reside in:

/private

I'm using FormsAuthentication to protect the pages in /private. I've
created a login page (login.aspx) which resides in /public. When trying
to access a page in /private, the browser is referred back to
/public/login.aspx, where the user is authenticated and sent back to
the referring page in /private. Great, it all works....BUT... when a
user goes directly to /public/login.aspx and authenticates, they are
referred to /public/Default.aspx. Dang! Well, fair enough, I'm using:

FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, False)

and if there is no referring URL then it has to use a default.

What I want to happen, is when there is no referring URL, the user
should be forwarded to say, /private/profile.aspx.
Does anyone know a way of overriding the default?

Thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top