简体   繁体   English

有关创建没有默认ASP.Net成员资格提供程序的MVC3登录系统的任何教程?

[英]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.

相关问题 ASP.NET MVC3用户登录 - ASP.NET MVC3 User Login ASP.NET MVC3教程您未创建的第一个ASP.NET MVC - ASP.NET MVC3 Tutorials Your First ASP.NET MVC not Create 调试ASP.NET MVC3自定义成员资格提供程序 - Debugging ASP.NET MVC3 custom membership provider 没有外部登录提供程序的 ASP.NET Core MVC 2.2 登录 - ASP.NET Core MVC 2.2 login without external login providers 帮助我决定是使用ASP.NET默认成员资格/角色提供程序还是编写自定义提供程序 - Help me decide whether to use ASP.NET default membership/roles providers or write custom providers 默认登录asp.net MVC3重定向到错误的视图。 这个在哪里? - Default Login asp.net MVC3 redirect to wrong view. Where is this set? ASP.NET MVC登录控制器方法没有使用自定义成员资格提供程序? - ASP.NET MVC login controller method without using a custom membership provider? ASP.NET MVC3自定义成员资格提供程序 - 指定的成员资格提供程序名称无效 - ASP.NET MVC3 Custom Membership Provider - The membership provider name specified is invalid 使用ASP.Net成员资格提供程序登录问题的MVC 3应用程序 - MVC 3 Application With ASP.Net Membership Provider Login Issue asp.net mvc 站点是否有任何搜索引擎提供商? - Is there any Search engine providers for asp.net mvc site?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM