473,397 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

using Forms Authentication

VR
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'
directory in realtion to my virtual directory:
"/public/default.aspx". In IIS I set the default document
to be "/public/default.aspx".

The problem is that once user is authenticated, ASP.NET
redirects him to "default.aspx" instead
of "public/default.aspx". MSDN says that "if there is no
original URL, Default.aspx is used" for
FormsAuthentication.GetRedirectUrl(...). How can I
customize the path to my default page?

Here is the code I use to authenticate a user and forward
him to the previously requested page:

FormsAuthenticationTicket oTicket =
new FormsAuthenticationTicket(szLogin, false, 1);

string szTicket =
FormsAuthentication.Encrypt(oTicket);

Response.Cookies.Add(
new HttpCookie(
FormsAuthentication.FormsCookieName, szTicket ));

string szURL =
FormsAuthentication.GetRedirectUrl(szLogin, false);

Response.Redirect(szURL);

Thanks,
VR
Nov 18 '05 #1
2 1478
"VR" <an*******@discussions.microsoft.com> wrote in message
news:04****************************@phx.gbl...
Hi,

I am using Forms type of authentication, but having
problems redirecting users to default page after they get
authenticated.


What if the user doesn't want to go to your default page?

The way Forms Authentication works is that when a user tries to go to a page
which requires authentication and they're not authenticated, they get
redirected to your login page instead. The redirection includes the desired
page in the ReturnUrl query parameter. When they've authenticated, they're
meant to be redirected to the page they requested.

When MSDN says "if there is no original URL", they're referring to the case
where the user goes directly to your login page, so that there is no
ReturnUrl parameter. In this case, the default is to go to default.aspx. You
can change this by "manually" checking to see if there's a ReturnUrl
parameter. If there isn't, you can redirect to "/public/default.aspx".

BTW, the default document in IIS is just a file name and extension, not a
path. It simply says what file name IIS will request when the user
specifies, e.g., http://yoursite/ and doesn't specify a file name.
--
John

Nov 18 '05 #2
Vic
Thanks, John.

I wasn't really clear explaining the problem. I do realize that an empty
ReturnUrl parameter is an exceptional case, occuring when the user goes
directly to the authentication page. I was trying to figure out whether it's
possible to somehow change the behavior of GetRedirectUrl() to return a page
that I consider a default.

Just like you said, I can always check ReturnUrl and manually set it. I
didn't care much for this approach because that would imply that I am
hardcoding that page that I consider a default. So, I thought maybe there is
a way to alter the bahavior of GetRedirectUrl() by tweaking something in
either web.config or in IIS.

Or, I just realized, I guess I could just add a key to web.config myself,
read it in, and use it in my app, instead of hardcoding it.

Thanks again.

VR

"John Saunders" <john.saunders at surfcontrol.com> wrote in message
news:OI**************@TK2MSFTNGP11.phx.gbl...
"VR" <an*******@discussions.microsoft.com> wrote in message
news:04****************************@phx.gbl...
Hi,

I am using Forms type of authentication, but having
problems redirecting users to default page after they get
authenticated.
What if the user doesn't want to go to your default page?

The way Forms Authentication works is that when a user tries to go to a

page which requires authentication and they're not authenticated, they get
redirected to your login page instead. The redirection includes the desired page in the ReturnUrl query parameter. When they've authenticated, they're
meant to be redirected to the page they requested.

When MSDN says "if there is no original URL", they're referring to the case where the user goes directly to your login page, so that there is no
ReturnUrl parameter. In this case, the default is to go to default.aspx. You can change this by "manually" checking to see if there's a ReturnUrl
parameter. If there isn't, you can redirect to "/public/default.aspx".

BTW, the default document in IIS is just a file name and extension, not a
path. It simply says what file name IIS will request when the user
specifies, e.g., http://yoursite/ and doesn't specify a file name.
--
John

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Billy Jacobs | last post by:
I have a website which has both secure and non-secure pages. I want to uses forms authentication. How do I accomplish this? Originally I had my web.config file in the root with Forms...
2
by: Summa | last post by:
Hi, In ASP.NET, i've written a class that handles URLRewrite. So that all requests to say "default.aspx?id=2&basic=1" is returned as "basic.1/2.aspx". It works beautifully...But but but....Using...
4
by: Dave | last post by:
Hi, Is there anyway to mimic forms authentication's loginUrl and RedirectFromLoginPage functionality using Windows authentication? We are developing intranet sites using basic authentication...
2
by: Eric | last post by:
I am trying to build an app where the stuff in the root directory is open to all, but anything under the Restricted directory requires you to login and I want to use Forms to do it. I'm having...
5
by: Gavin Stevens | last post by:
I'm trying to figure out the ASP.NET Forms Auth I have 3 or 4 pages i want to allow anonymous access to.. Then I have 5 or 6 pages I placed in another directory in the webproject. These I want...
3
by: Sharat Koya | last post by:
Please can you help with a problem I am having. My web config is set to... <authorization><deny users="?"/> <authentication mode="Forms"> <forms name=".COOKIE" loginUrl="login.aspx"...
3
by: Stu Lock | last post by:
Hi, Is there a way of requiring a log in for individual asp.net pages rather than securing a entire directory. I have a web app where there are 100+ pages but only 2 need to be password...
2
by: Evan Basalik | last post by:
I have an ASP.NET application which uses forms authentication. For some reason, after someone logs in, they get a Windows logon dialog whenever they try to access any ASPX files in the...
2
by: thechaosengine | last post by:
Hi eveyone, If anyone could advise on the following I would be truly greatful: I have a fairly standard set up. An IIS 5.1 website set up with anonymous access allowed in all areas of the site...
1
by: Ofer_Adivi | last post by:
I'm using Forms Authentication in my site. And my login page did not show the images at run time. while i'm drop the Forms Authentication it seems to be good. This is my Code <authentication...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.