Developer Forum »
Webnodes authentication (code-behind)
42 posts

How do you authenticate a user in code-behind?

Currently going with:

new WAFMembershipProvider().ValidateUser(username, password),

but this does not seem to update the IPrincipal User object's Name-property nor WAFContext.Session.GetUser() (postback does not occur). Do I have to validate the user and then make a query for the user in order to obtain the correct username and name?

Thanks

-Emil

120 posts

To authenticate (to check combination of username and password) you can use these methods:

Membership.ValidateUser(userName, password); // any provider

WAFMembershipProvider().ValidateUser(username, password); // directly on the WAF provider

WAFRuntime.Engine.AutenticateUser(...) // gives same result

user.Password.Test() // if you already got the user

 

To log in a user:

 if (Membership.ValidateUser(userName, "password")) {

     FormsAuthentication.SetAuthCookie(userName, true);

     Response.Redirect("~/page.aspx");

 }

 

42 posts

The problem being that I cannot redirect (log-in via Ajax). When ValidateUser() completes, I am successfully logged in if redirected (i.e. next page load) . But if I am not redirected, the User object is not updated by WAF it would seem...

Not a big deal, I know. Just wanted to know if I was going about it the right way!

 

:)

120 posts

ok!

The login relies on cookies set by the standard ASP.Net membership provider. Setting cookies with AJAX is possible ( also Javascript), but I think it is tricky business and you are moving away from the standard API.Net way of doing it.  You would need to spend some time researching the way the ASP.Net membership uses cookies.

In any case it is not a Webnodes related issue, as we are just implementing the standard provider. (The same issues would apply to any system out there using the ASP.Net membership provider.)

Ole

1