Web API in MVC solution in separate project

后端 未结 8 1210
Happy的楠姐
Happy的楠姐 2020-12-02 04:35

I am creating a new MVC4 project, and research has lead me to believe that communicating from javascript to the server side is better achieved now through web API framework

8条回答
  •  孤街浪徒
    2020-12-02 05:13

    In addition to setup the separate DLL for the Web.Api.

    Just a Suggestion:

    1. Create the Project
    2. Nugget WebActivatorEx
    3. Create a a class Method to be called upon app_start

      [assembly: WebActivatorEx.PostApplicationStartMethod(typeof(API.AppWebActivator),"Start")]

      [assembly:WebActivatorEx.ApplicationShutdownMethod(typeof(API.AppWebActivator), "Shutdown")]

    4. Register a web.api routes inside the Start Method

      public static void Start() { GlobalConfiguration.Configure(WebApiConfig.Register); }

    5. Reference the Project to the Web Project. to activate the Start Method.

    Hope this helps.

提交回复
热议问题