473,386 Members | 1,828 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,386 software developers and data experts.

FormsAuthentication.RedirectFromLoginPage alternative?

Is FormsAuthentication.RedirectFromLoginPage the only way to populate the
HttpContext.Current.User.Identity.Name property?

A base class for each page contains the follwoing property:

public int CustomerID {
get {
try {
if (HttpContext.Current.User.Identity.Name != "")
return Convert.ToInt32(HttpContext.Current.User.Identity. Name);
else
return 0;
}
catch {
return 0;
}
}
set {
FormsAuthentication.RedirectFromLoginPage(value.To String(), false);
}
}

Is there are more direct way of storing the ID of the logged in user,
without invoking the "redirect from login page" functionality? I have my own
logic for redirecting on successfull login.

I don't use a dedicated login page, instead I have a user control on the
right of every non-secure page, which houses login/password controls. This
control is then dynamically replaced with another control, after a user has
logged in and wants to visit secure pages (checkout, account details etc).

Bascially, I want to use Forms Auhtentication without a dedicated login
page, and without having to redirect when I set my CustomerID property to
the ID of a given customer.

I know this is fairly non-standard, but my client is very insistent on
having it his way.

Kind regards

Ben
Nov 18 '05 #1
2 6992
You can use FormsAuthentication.SetAuthCookie(value.ToString() , false);

You probably need to realize that the cookie won't be set until you do
redirect/end the stream...like any good cookie...

Would that do the trick?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Ben Fidge" <be*******@btopenworld.com> wrote in message
news:u1**************@tk2msftngp13.phx.gbl...
Is FormsAuthentication.RedirectFromLoginPage the only way to populate the
HttpContext.Current.User.Identity.Name property?

A base class for each page contains the follwoing property:

public int CustomerID {
get {
try {
if (HttpContext.Current.User.Identity.Name != "")
return Convert.ToInt32(HttpContext.Current.User.Identity. Name); else
return 0;
}
catch {
return 0;
}
}
set {
FormsAuthentication.RedirectFromLoginPage(value.To String(), false); }
}

Is there are more direct way of storing the ID of the logged in user,
without invoking the "redirect from login page" functionality? I have my own logic for redirecting on successfull login.

I don't use a dedicated login page, instead I have a user control on the
right of every non-secure page, which houses login/password controls. This
control is then dynamically replaced with another control, after a user has logged in and wants to visit secure pages (checkout, account details etc).

Bascially, I want to use Forms Auhtentication without a dedicated login
page, and without having to redirect when I set my CustomerID property to
the ID of a given customer.

I know this is fairly non-standard, but my client is very insistent on
having it his way.

Kind regards

Ben

Nov 18 '05 #2
Cheers Karl,

I discovered that method earlier. It also occured to me about the round-trip
(server->client->server). I was using Server.Transfer to make use of
Context.Items[] to pass serialized objects between pages. When I converted
my app to use Response.Redirect it now works fine. The only caveat is that
in order to pass objects between pages (I *hate* querystrings) I've got to
use Session[] now.

Thanks for the info anyway!

Ben
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:OL**************@tk2msftngp13.phx.gbl...
You can use FormsAuthentication.SetAuthCookie(value.ToString() , false);

You probably need to realize that the cookie won't be set until you do
redirect/end the stream...like any good cookie...

Would that do the trick?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Ben Fidge" <be*******@btopenworld.com> wrote in message
news:u1**************@tk2msftngp13.phx.gbl...
Is FormsAuthentication.RedirectFromLoginPage the only way to populate the
HttpContext.Current.User.Identity.Name property?

A base class for each page contains the follwoing property:

public int CustomerID {
get {
try {
if (HttpContext.Current.User.Identity.Name != "")
return

Convert.ToInt32(HttpContext.Current.User.Identity. Name);
else
return 0;
}
catch {
return 0;
}
}
set {
FormsAuthentication.RedirectFromLoginPage(value.To String(),

false);
}
}

Is there are more direct way of storing the ID of the logged in user,
without invoking the "redirect from login page" functionality? I have my

own
logic for redirecting on successfull login.

I don't use a dedicated login page, instead I have a user control on the
right of every non-secure page, which houses login/password controls.
This
control is then dynamically replaced with another control, after a user

has
logged in and wants to visit secure pages (checkout, account details
etc).

Bascially, I want to use Forms Auhtentication without a dedicated login
page, and without having to redirect when I set my CustomerID property to
the ID of a given customer.

I know this is fairly non-standard, but my client is very insistent on
having it his way.

Kind regards

Ben


Nov 18 '05 #3

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

Similar topics

3
by: Phil Certain | last post by:
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
2
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: ...
8
by: Andy Sutorius | last post by:
Hi, For some reason the login.aspx webpage redirects to itself after a successful login and not to the url in the address bar. I have stepped through this with debug and it behaves as it is...
2
by: Grant Merwitz | last post by:
Hi, i am using forms authentication in an ASP.NET project I am setting the Forms authentication cookie by using: FormsAuthentication.RedirectFromLoginPage(UserName.Text, false); Now when i...
5
by: BoltonWolf | last post by:
Hi, I have a ASP.Net web site, that we sell as a module to our core software, versions of this site are running fine on many servers, however we are having problems with our latest installtion,...
1
by: Dean R. Henderson | last post by:
I setup FormsAuthentication on a couple websites where it has been working as expected for a long time. I used this code to setup the same type of authentication on a new website I am working on...
1
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...
0
by: Imran Aziz | last post by:
Hello All, I cannot seem to get createPersistentCookie option of FormsAuthentication.RedirectFromLoginPage work. Even if I set it to true the cookie is setup to expire after 30 min ( default...
2
by: rn5a | last post by:
A web.config file has the following code: <configuration> <system.web> <authentication mode="Forms"> <forms name="NETConnectCookie" loginUrl="Login.aspx"> <credentials passwordFormat="SHA1"/>...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.