![]() |
|
|
|||||||
![]() |
ASP Net - Using FormsAuthentication - how to override default referral |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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 |
|
|
|
|
#2 |
|
Posts: 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" <> 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 |
|
|
|
#3 |
|
Posts: 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" <> 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. |
|
|
|
#4 |
|
Posts: 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" <> 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 |
|
![]() |
| Thread Tools | Search this Thread |
|
|
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 |