views:

254

answers:

5

Ok, i have simple scenario:

have two pages: login and welcome pages. im using FormsAuthentication with my own table that has four columns: ID, UserName, Password, FullName

When pressed login im setting my username like:

FormsAuthentication.SetAuthCookie(userName, rememberMe ?? false);

on the welcome page i cant use:

Page.User.Identity.Name

to provide to user which user currently logged, BUT i dont user username like at all examples in http://asp.net web site i want to user FullName field

i think that always go to db and request fullname when page loads its crazy and dont like to user Sessions or Simple Cookie mayby FormsAuth provider has custom fields for this

+1  A: 

Forms authentication works using cookies. You could construct your own auth cookie and put the full name in it, but I think I would go with putting it into the session. If you use a cookie of any sort, you'll need to extract the name from it each time. Tying it to the session seems more natural and makes it easy for you to access. I agree that it seems a waste to go back to the DB every time and I would certainly cache the value somewhere.

Info on constructing your own forms authentication cookie can be found here.

tvanfosson
A: 

There are no custom fields for forms authentication. You'll just have to use session. That's what it's there for you know. ;) Just don't forget - forms authentication cookie and session are two independant things. They even each have their own timeouts. So the session won't be reset when a user logs out unless you do so yourself.

Vilx-
yes but it will reset when i will reset IIS :(
msony
+1  A: 

I would store the user's full name in the session cookie after your call to FormsAuth

FormsAuth.SetAuthCookie(userName, rememberme);

// get the full name (ex "John Doe") from the datbase here during login
string fullName = "John Doe";

Response.Cookies["FullName"].Value = fullName;
Response.Cookies["FullName"].expires = DateTime.Now.AddDays(30);

and then retrieve it in your view pages via:

string fullName = HttpContext.Current.Request.Cookies["FullName"].Value
Todd Smith
A: 

What about using Profiles to store the extra info with the User?

Mike Kingscott
A: 

The simplest option is to use the session. By default session state is stored in memory and will be lost when the ASP.NET worker process recycles, however you can configure it to use state service instead, which retains session info in a separate process:

http://msdn.microsoft.com/en-us/library/ms178586.aspx

Another option would be to use profiles. As it sounds like you already have 'profile' information stored in your own tables, you'd probably have to write a custom provider for it so it's a more complex solution.

richeym