taz8020
asked on
asp.net custom Authentication
Hi I have build a class to create a user, block user and so on. That all works well. The reason i went down this route is we have over 10,000 customers and want to email them all with generated passwords. So we will set up all existing customers for our new site.
How do I set the user as Authenticated = true and username.
I was using the asp.net way and all was working well untill I wanted generate users on our internal system.
So all I really want to do is set the username, userid, role and then mark the user as Authenticated when my class returns that the login in was a match.
This way i can use the code asp uses to log them out but can do what I need.
Hope this makes sense.
How do I set the user as Authenticated = true and username.
I was using the asp.net way and all was working well untill I wanted generate users on our internal system.
So all I really want to do is set the username, userid, role and then mark the user as Authenticated when my class returns that the login in was a match.
This way i can use the code asp uses to log them out but can do what I need.
Hope this makes sense.
Use FormsAuthentication class, see here a simple example:
http://msdn.microsoft.com/en-us/library/xdt4thhy(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/xdt4thhy(v=vs.85).aspx
ASKER
on my custom form i dont have e.Authenticated = True how can i do this.
I would like to be able to set the membership but if not some how set Authenticated = True as i think it will work quite well then i can store the userid in a sesion varible.
I would like to be able to set the membership but if not some how set Authenticated = True as i think it will work quite well then i can store the userid in a sesion varible.
You need to create an identity object and assign it as the user to the current HttpContext object.
You can then also save the pricipal as a session object should you wish.
GenericIdentity i = new GenericIdentity("Username");
GenericPrincipal principal = new GenericPrincipal(i, new string[]{"AdminRole"});
HttpContext.Current.User = principal;
if (Request.IsAuthenticated)
{
Response.Write("Authenticated");
}
You can then also save the pricipal as a session object should you wish.
HttpContext.Current.User = principal;
Session["_principal"] = principal
Check my example link:
If ((UserEmail.Text = "jchen@contoso.com") And _
(UserPass.Text = "37Yj*99Ps")) Then
FormsAuthentication.Redire ctFromLogi nPage _
(UserEmail.Text, Persist.Checked)
Else
Msg.Text = "Invalid credentials. Please try again."
End If
If ((UserEmail.Text = "jchen@contoso.com") And _
(UserPass.Text = "37Yj*99Ps")) Then
FormsAuthentication.Redire
(UserEmail.Text, Persist.Checked)
Else
Msg.Text = "Invalid credentials. Please try again."
End If
Hi Taz,
Re:
If you open the asp .net database do the users you created exist in the table aspnet_users and do the userids' exist in the table aspnet_membership?
Alan
Re:
I was using the asp.net way and all was working well untill I wanted generate users on our internal system.Wondering how you created users, if not the asp .net way?
If you open the asp .net database do the users you created exist in the table aspnet_users and do the userids' exist in the table aspnet_membership?
Alan
ASKER
Hi, no have created a new table very similar to asp.net but membership is not needed. So when someone logs on is gets all their details returned in a class. like
Public Class UserDetails
Public Property UserID As Guid
Public Property UserName As String
Public Property Email As String
Public Property DOB As Date
Public Property Tel As String
Public Property Mobile As String
Public Property LastActivityDate As Date
Public Property LastLoginDate As Date
Public Property TimeTaken As TimeSpan
Public Property HadErrors As Boolean = False
Public Property ErrorMessage As String = ""
End Class
Was goint to put this in a session vaible but did not know if that was the best way. Thought i might be able to manually set HttpContext.Current.User = userid or the name and email. Plus my form does not have e As AuthenticateEventArgs so cannot set e.Authenticated = True
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi Taz,
still wondering:
If you open the asp .net database do the users you created exist in the table aspnet_users and do the userids' exist in the table aspnet_membership?
Trying to establish if your class implements the asp .net membership server?
Respectfully yours,
Alan
still wondering:
If you open the asp .net database do the users you created exist in the table aspnet_users and do the userids' exist in the table aspnet_membership?
Trying to establish if your class implements the asp .net membership server?
Respectfully yours,
Alan
Open in new window
Modify global.asax Global.Application_Authent
Open in new window
You can access properties elsewhere in your code like this:
Open in new window
How to implement forms based authentication:
http://support.microsoft.com/kb/301240