By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,844 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

Using FormsAuthentication - how to override default referral

P: n/a
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(txtUsern ame.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.

Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

"Phil Certain" <c9******@fastmail.co.uk> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
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(txtUsern ame.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.

Nov 19 '05 #2

P: n/a
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" <c9******@fastmail.co.uk> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
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(txtUsern ame.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.

Nov 19 '05 #3

P: n/a
Hi William,

Many thanks for this - it works exactly as required.

Phil
William F. Robertson, Jr. wrote:
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" <c9******@fastmail.co.uk> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
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(txtUsern ame.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.


Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.