473,503 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.

Nov 19 '05 #1
3 3594
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1921
by: Mike | last post by:
I want to exempt an entire subdirectory "/help" from the need for FormsAuthentication. How can I do it? I am using .Net FormsAuthentication to require login to all non member pages in my...
2
1481
by: VR | last post by:
Hi, I am using Forms type of authentication, but having problems redirecting users to default page after they get authenticated. My default page is default.aspx, but it's in 'public'...
3
2549
by: T. Regan | last post by:
I have a test app where I have Forms Authentication set up. When I build and run the app as http://localhost/testapp/login.aspx, it runs correctly. I get the login prompt and the proper...
0
348
by: Ed West | last post by:
Hello This SignOut code is not working, people are still logged in after it redirects to default.aspx. any ideas? Thanks. public class logout : System.Web.UI.Page { private void...
2
3485
by: tshad | last post by:
I have a logon page that is may be called by the Forms Authentication setup. This would put a ReturnURL as part of the URL. I would normally then just issue a: ...
1
1540
by: Alex Nitulescu | last post by:
Hi. I have two questions, please: a) If I go DIRECTLY to Login, there's no Request.Params("ReturnURL"), and therefore RedirectFromLogin won't work, because it will try to go to a page named...
1
3750
by: Jeremy Chapman | last post by:
I have built a web app. While testing I have found that if I browse to a page in the app, then get redirected to the login page and enter my credentials. The...
5
4824
by: Åženol Akbulak | last post by:
Hello; I use in my web application FormsAuthentication. Also I use Session state (InProc). When a user logged in, I can read Session parameters. (For example Session). Problem is that, when...
0
1066
by: Keithb | last post by:
I am using the login control on my web site, which has both authenticated an unauthenticated users. I added a logout page that is supposed to allow an authenticated user to drop his authentication...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7006
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5021
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1519
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
397
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.