Reputation: 778
I am developing a web site with using ASP.NET MVC 5 and WEB API template. I use individual accounts feature of this template. However, WEB API has its own account controller and controls authentication mechanism using it. ASP.NET MVC 5 also has its own account controller.
How can i use both staff in the same authentication mechanism. Or are they in the same authentication, although they use different accountcontroller from each other?
Upvotes: 1
Views: 2533
Reputation: 4450
The answer to your question is rather simple. You need both account controllers so that clients calling the MVC controller (e.g. browsers) and clients calling the web api controller (e.g. ajax requests, fiddler etc) can authenticate.
If both controllers are part of the same domain and application then they by default use the same authentication mechanism behind the scenes, even though you can still override this behaviour.
Upvotes: 3
Reputation: 2685
From your question, I take it as you would like to host your website using MVC at a domain, say www.mysite.com. If that's the case, then you can host your Web API project in a subdomain such as api.mysite.com.
Since authentication in the parent domain can propogate to subdomains, you can disable authentication mechanism of the Web API and use the authentication of MVC project only. At least, this is how I achieved it with two MVC projects when I hosted a forum project as a subdomain of my website.
Upvotes: 1