500 - 使用webapi控制器时出现内部服务器错误

时间:2018-02-01 09:42:15

标签: asp.net-mvc asp.net-web-api

我将webapi控制器添加到项目中,当然用于处理webapi方法路径,我在WebApiConfig.cs内的代码下面使用 App_Start 文件夹:

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

和这一行

GlobalConfiguration.Configure(WebApiConfig.Register);

进入 Global.asax ,例如下面的代码:

protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        GlobalConfiguration.Configure(WebApiConfig.Register);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
    }

现在项目当前在 localhost 中运行,但在服务器获取错误:

  

服务器错误

     

500 - 内部服务器错误。

     

您要查找的资源存在问题,无法显示。   我在IIS中重新启动应用程序并重新启动IIS但不解决。

如何解决这个问题?

UPDATE1: 我通过失败的请求跟踪规则记录IIS错误并获取logs.Logs如下图所示:

enter image description here

我搜索了标签中的主要错误,但没有找到它。

什么消息是一般错误?

0 个答案:

没有答案
相关问题