1

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?

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

Correct if I`ve misunderstood, but if you disable authentication in Web API, people will be able to access to your Web Api methods without authorization.
Sorry for missing information, but I assumed that the OP meant Forms Authentication. So when using Forms Authentication, the authentication cookie generated for the parent side grants access to subdomains too. Of course, Web API methods will require authentication, but the user won't need to authenticate for Web API too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.