WebApi's {“message”:“an error has occurred”} on IIS7, not in IIS Express

后端 未结 9 1965
滥情空心
滥情空心 2020-12-12 10:36

I\'m working with ASP.NET MVC 4 WebApi and am having a lot of fun with it running it on my local computer on IIS Express. I\'ve configured IIS Express to serve remote machi

9条回答
  •  佛祖请我去吃肉
    2020-12-12 11:23

    None of the other answers worked for me.

    This did: (in Startup.cs)

    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            var config = new HttpConfiguration();
    
            WebApiConfig.Register(config);
    
            // Here: 
            config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
        }
    }
    

    (or you can put it in WebApiConfig.cs):

    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            // Web API routes
            config.MapHttpAttributeRoutes();
    
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
    
            // Here: 
            config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
        }
    }
    

提交回复
热议问题