简体   繁体   中英

How do I use ASP.NET Identity across my MVC and WebAPI?

As a warning, I am very new to ASP.NET Identity. I have a project I am working on, and am trying to create different projects to better organize it. I have my UI layer, which is an MVC5 project, and my WebAPI, which is the API that will get called to perform various actions.

I want to use ASP.NET Identity 2.0 to authenticate and authorize actions in both projects. What is the proper way to do this?

I have two projects in the same solution. Let's say that I run debugging for both of the projects, I want to test being able to authenticate in the UI, then try and access a protected API call and see if it works.

However, if the Identity information is configured in the UI (using the default template), how do I make sure the API properly authenticates users?

One approach is to perform all user actions via the Web API, including authentication and authorization, as well as other Identity-related tasks such as registering and confirming new user accounts. This way, your presentation layer (whether it is a web, desktop or mobile application) will be responsible only for interacting with your API and presenting the data (as it supposed to be).

Check out this series of blog posts that demonstrate how to implement this approach using ASP.NET Web API and AngularJS.

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