Web Api and MVC Individual Account

in visual studio 2013 i've created a web api project (selecting also mvc framework in the wizard)

Anyway in the Controllers i've only the AccountController class derived from ApiController

public class AccountController : ApiController

It's possible, in the same project, have a mvc controller and api controller? How can i handle the authentication (signup, login,ecc...) with api controller and mvc controller?

The wizard generate only the apicontroller


you can certainly create a new MVC controller with the same name, as long as your route configurations dontcreate any clashes. The MVC controller will implement Controller rather than ApiController.

As you may expect, you will need to make sure you dont have any namespace clashes either.

For authentication there are separate AuthorizeAttributes you can use. The one in System.Web.Http is for WebAPI and the one for MVC can be found in System.Web.MVC

链接地址: http://www.djcxy.com/p/20394.html

上一篇: MVC4 Web API默认JSON序列化程序

下一篇: Web Api和MVC个人帐户