HOWTO: Programmatically Login User in ASP.Net 2.0

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?
 
B

brenton

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top