简体   繁体   中英

How to create proper login to access trough [Authorize] (MVC database-first)

I'm new to MVC and so far I've created some pages. As I only want to let members access to the site I've added [Authorize] for these pages so other are redirected to to login/register page. But I've no clue about the next steps.

How do I give authorization upon success login? Do I use session for the current logged user?

I got MVC template which already have its own login, but I want to create my own, using database(database-first) to get better understanding.

Any help is much appreciate. Thanks.

Using below article where you can learn how to integrate existing database in ASP.NET MVC 5 web application using ADO.NET database first approach and how to configure simple login work flow for integrating existing logins with the ASP.NET MVC 5 web application with OWIN middle ware secure authorization mechanism.

Article : Integrating Existing Database With Login Using ADO.NET Database First Approach

    [Authorize]  
    public class HomeController: Controller  
    {  
       public ActionResult Index()  
        {  
            return this.View();  
        }
    }  

Note :

used [Authorize] attribute at controller level to secure access to Home controller for authenticated users only .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM