简体   繁体   中英

Using MVC5 and Web API 2 in the same project

I'm about to start a new project in ASP.NET MVC5, which has a bit of Web API too. I'll also need a Windows Forms client which will call the API. This client has a file system watcher that detects when a file has been changed, and will post the contents to the API.

When the API receives the data, it does some calculations, and ideally will send the results through SignalR to the browser and update the display.

I'm getting rather stuck trying to work out the authentication. I want to use Individual User Accounts, so the user can log in with the Windows Forms client (and get a token) and in the browser to view the data.

I've got as far as File -> New -> Project, and tried an MVC project with the Web API box checked, and a Web API with the MVC box checked. Looking at the two AccountController classes that these generate, they seem quite different.

I guess the options are

  1. Try to get these two controllers working together
  2. Call the MVC controller from the Windows Forms client
  3. Have two projects in the solution and try to work out how to use SignalR to talk between them.
  4. A better way?

I suspect the last one. I've not used Web API before, so I could be doing this all wrong. What approach should I take?

I would say, create 2 different projects, 1 for MVC 1 for API. Use 1 BLL which is referenced in both of them and carries the logic for both of them and will not be dealing with separate controllers.

Of course if you need other layers like DataAccess or Repository, you have to create them once and they will be referenced in the BLL which is later referenced in both MVC and API interfaces.

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