HOWTO: Programmatically Login User in ASP.Net 2.0

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to bypass requiring the intranet domain user to type in a username and
password when coming to my website, even the very first time.

If it's the first time I do a Membership.CreatUser passing the username,
gotten from ServerVariables("LOGON_USER"), a constant password (all users
have the same password), and an email address built with the username and a
constant domain name from the intranet.

However, things like User.Identity.Name are still blank.

How do I programmatically login a user so that everything acts just like
when the user enters his username and password on a 'Login.aspx' page?
 
Yo,

What you have to do is set an authentication cookie by doing the
following:

[c#]
FormsAuthentication.SetAuthCookie(userName, bool);

This way asp.net will load up the information for that username's info,
profile, etc.

If you need to manually load up the profile and gather some info first
before you do anything, use this:

ProfileCommon thisProfile = Profile.GetProfile(userName);

Good luck.

-Brenton
 
Thank you for the response. I'll try your recommendation(s).

--
Thank you kindly,

Dan Sikorsky BA, BSCE, MCS


Yo,

What you have to do is set an authentication cookie by doing the
following:

[c#]
FormsAuthentication.SetAuthCookie(userName, bool);

This way asp.net will load up the information for that username's info,
profile, etc.

If you need to manually load up the profile and gather some info first
before you do anything, use this:

ProfileCommon thisProfile = Profile.GetProfile(userName);

Good luck.

-Brenton
 
Back
Top