[英]Any tutorials on creating an MVC3 login system without the default ASP.Net membership providers?
I'm looking for a tutorial or small introductory guide on creating a login system for ASP.Net MVC3 without using the default ASP.Net membership provider. 我正在寻找关于为ASP.Net MVC3创建登录系统的教程或小型入门指南,而不使用默认的ASP.Net成员资格提供程序。
I've created a new MVC3 project with the Internet Application template, and here is the contents of _LogOnPartial.cshtml: 我用Internet应用程序模板创建了一个新的MVC3项目,这里是_LogOnPartial.cshtml的内容:
@if(Request.IsAuthenticated) {
<text>Welcome <strong>@User.Identity.Name</strong>!
[ @Html.ActionLink("Log Off", "LogOff", "Account") ]</text>
}
else {
@:[ @Html.ActionLink("Log On", "LogOn", "Account") ]
}
Is @User.Identity.Name
part of the membership provider? @User.Identity.Name
是会员提供者的一部分吗? I'd like to read some more on membership on ASP.Net MVC3, since I already have a database in place with user credentials, I do not need the prapackaged one. 我想阅读更多有关ASP.Net MVC3成员资格的内容,因为我已经拥有一个带有用户凭据的数据库,我不需要使用prapackaged。
Thank you! 谢谢!
Its actually fairly easy to implement custom authentication code in ASP.NET MVC. 它实际上很容易在ASP.NET MVC中实现自定义身份验证代码。
In the LogOn
method of your controller you'll need to call the FormsAuthentication provider after you have authenticated the user's credentials. 在控制器的
LogOn
方法中,您需要在验证用户的凭据后调用FormsAuthentication提供程序。
public ActionResult LogOn(LogOnModel model)
{
//Handle custom authorization then call the FormsAuthentication provider
FormsAuthentication.SetAuthCookie(/*user name*/, true);
//Return view
}
After this method call, The User.Identity.Name will be populated, and you can utilize the AuthorizeAttribute
on your controllers or controller methods. 调用此方法后,将填充User.Identity.Name,您可以在控制器或控制器方法上使用
AuthorizeAttribute
。
In the LogOff
method of your controller you'll call the FormsAuthentication provider again 在控制器的
LogOff
方法中,您将再次调用FormsAuthentication提供程序
public ActionResult LogOff()
{
FormsAuthentication.SignOut();
//Return view
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.