Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Is it possible to log a user (NOT a member) in programatically in umbraco 4.0.2.1 or 4.0.3 ?
Do you actually need to log them in (load any cookies, etc) or do you just need a reference to the User object that represents them?
If it's the latter you could do new User(some id).
if you need to log the use in you need to take the BackofficeMembership provider and call the ValidateLogin-Method on it like this
Membership.Providers[UmbracoSettings.DefaultBackofficeProvider].ValidateUser(USERNAME, PASSWORD)
if that succeedes get the user and add the login to the database
BusinessLogic.User u = new User(USERNAME);
Guid userContextId = Guid.NewGuid();SqlHelper.ExecuteNonQuery( "insert into umbracoUserLogins (contextID, userID, timeout) values (@contextId,'" + u.Id + "','" + (DateTime.Now.Ticks + (_ticksPrMinute * _umbracoTimeOutInMinutes)).ToString() + "') ", SqlHelper.CreateParameter("@contextId", userContextId));
And then add a cookie with the context
HttpCookie cookie = new HttpCookie("UserContext");cookie.Name = "UserContext";cookie.Value = value;cookie.Expires = DateTime.Now.AddDays(1);HttpContext.Current.Response.Cookies.Add(cookie);
The codes are taken from the login.aspx.cs and BasePage.cs you can take a look yourself
Hope thats what you wanted :)
Toby
I wish i could mark both suggestions as "solution".
thank you both
Mikael
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Logging user in programatically ?
Is it possible to log a user (NOT a member) in programatically in umbraco 4.0.2.1 or 4.0.3 ?
Do you actually need to log them in (load any cookies, etc) or do you just need a reference to the User object that represents them?
If it's the latter you could do new User(some id).
if you need to log the use in you need to take the BackofficeMembership provider and call the ValidateLogin-Method on it like this
if that succeedes get the user and add the login to the database
And then add a cookie with the context
The codes are taken from the login.aspx.cs and BasePage.cs you can take a look yourself
Hope thats what you wanted :)
Toby
I wish i could mark both suggestions as "solution".
thank you both
Mikael
is working on a reply...