Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - Using FormsAuthentication - how to override default referral

 
Thread Tools Search this Thread
Old 01-18-2005, 08:56 AM   #1
Default Using FormsAuthentication - how to override default referral


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.



Phil Certain
  Reply With Quote
Old 01-18-2005, 09:22 AM   #2
Stuart A Hill
 
Posts: n/a
Default Re: Using FormsAuthentication - how to override default referral
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" <> wrote in message
news: 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.
>





Stuart A Hill
  Reply With Quote
Old 01-18-2005, 04:00 PM   #3
William F. Robertson, Jr.
 
Posts: n/a
Default Re: Using FormsAuthentication - how to override default referral
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" <> wrote in message
news: 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.
>





William F. Robertson, Jr.
  Reply With Quote
Old 01-18-2005, 06:19 PM   #4
Phil Certain
 
Posts: n/a
Default Re: Using FormsAuthentication - how to override default referral
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" <> wrote in message
> news: 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.
> >




Phil Certain
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Set default path of <input type = file> vj_india Software 1 09-15-2006 06:17 PM
Computer with default language in Chinese AG A+ Certification 3 04-04-2005 12:40 AM
Re: Default media player natural_4u A+ Certification 1 02-16-2004 09:35 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46