简体   繁体   中英

Having trouble starting .NET MVC project with Web Api integrated

I'm working on integrating an existing Web Api project into a .NET MVC (4.5.2) project. So far, I've copied in the WebApiConfig.cs (but am not yet referencing it from Global.asax.cs), as well as some exception logging/handlers from the Web Api project. I've also added a few required references - Microsoft.Data.OData , an updated version of Newtonsoft.Json , System.Web.Http.Formatting , System.Web.Cors , System.Web.Http.Cors and System.Web.Http .

The application doesn't start - no breakpoints in the handlers I added are hit, nor is Application_Start() ever hit. I'm having trouble nailing down the root cause here and am unsure how to debug this further.

Add this in your Global.asax.cs

void Application_Error(object sender, EventArgs e)
{
  Exception exception = Server.GetLastError();
}

then from there, you should be able to put a breakpoint on your global asax.cs and figure out what's the error.

Found the root cause. As a part of installation of one of the packages, this was added to the <system.webServer><handlers> section of my web.config.

<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />

The application at least starts now - we'll see if it presents problems when I finish fully integrating the Web Api project.

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