在asp.net Web表单和MVC中进行表单身份验证

时间:2014-08-27 18:22:48

标签: asp.net-mvc asp.net-mvc-4 forms-authentication asp.net-identity

我正在尝试重建现有的asp.net网络表单并创建一个新的mvc应用程序。我坚持认证用户。

在我使用的网络表单应用

public class UserPrincipal : System.Security.Principal.IPrincipal
public class UserIdentity : System.Security.Principal.IIdentity

声明自定义UserPrincipal和UserIdentity类。

在登录过程中,我正在使用

UserPrincipal mpUser = new UserPrincipal(userID);
if (mpUser != null)
                {
                    Context.User = mpUser;
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1,
                        userID.ToString(),
                        DateTime.Now,
                        DateTime.Now.AddMinutes(60),
                        false,
                       ((UserIdentity)Context.User.Identity).IdentityRolesToString(userID)
                        );

string encTicket = FormsAuthentication.Encrypt(authTicket);
HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
Response.Cookies.Add(faCookie);

身份验证过程是否仍然相同。我发现了很多关于SimpleMembership,Basic Membership,ASP.NET Membership的东西,但我很困惑这种技术是否过时或者有一种新的推荐方法可以做到这一点?

0 个答案:

没有答案