如何在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");
        }
    

    您可以在此处