如何在ASP.NET MVC 5中实现简单身份验证 [英] How to implement simple authentication in ASP.NET MVC 5

查看:139
本文介绍了如何在ASP.NET MVC 5中实现简单身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有SQL Server数据库的项目,一个带有数据库的EF的项目,一个是工作单元,另一个是服务层.我需要添加ASP.NET MVC项目并使用现有服务来验证用户身份.

I have existing project with a SQL Server database, EF with database first, unit of work and service layer. I need to add ASP.NET MVC project and use existing service to authenticate user.

我发现了不同的复杂决定.我需要在身份中使用我的服务或在没有身份的情况下实施身份验证.

I found different complicated decisions. I need to use my service in identity or implement authentication without identity.

推荐答案

请在 Nuget上尝试该软件包(AuthPackage) 它使您可以轻松地向asp.net mvc添加身份验证.

Please try this package on Nuget (AuthPackage) its enables you to add authentication to your asp.net mvc easily.

  1. 使用程序包管理器控制台"安装程序包:

  1. install package using Package Manager Console:

 Install-Package AuthPackage

  • 在(appSettings)中将连接字符串添加到Web.config:

  • add Connection String to your Web.config in (appSettings):

     <add key="connectionString" value="connectionStringHere" />
    

  • 您已经准备好注册用户,登录,注销

  • you're ready to register users, login, logout

    示例:

     public async Task<ActionResult> SignIn()
        {
            var context = System.Web.HttpContext.Current;
            AuthUser authUser = new AuthUser(context);
            await authUser.SignIn("waleedchayeb2@gmail.com", "123456");
            return RedirectToAction("Index", "Home");
        }
    

    您可以在此处

    这篇关于如何在ASP.NET MVC 5中实现简单身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆