错误请求webapi错误500

时间:2017-09-18 19:35:21

标签: c# asp.net-web-api cors

在我的webApi中,我有一个配置控制器,我想要make put request。它工作但响应错误500.我的前开发人员是angular2。 我尝试了几件事,但没有成功。

我正在使用包microsoft.AspNet.WebApi.Cors

在appStart中我有WebApiConfig类

 public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            config.EnableCors();

            // Web API routes
            config.MapHttpAttributeRoutes();
        }
    }

我的WebConfig

<system.webServer>
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
    <validation validateIntegratedModeConfiguration="false" />
    <modules>
      <remove name="ApplicationInsightsWebTracking" />
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
    </modules>
  </system.webServer>

ConfigurationController

 [EnableCors(origins: "*", headers: "*", methods: "*")]
    [RoutePrefix("api/v1/configuration")]
    public class ConfigurationController : ApiController
    {

        private readonly ConfigurationQueryHandler ConfigurationQueryHandler;
        private readonly ConfigurationCommandHandler configurationCommandHandler;

        public ConfigurationController(ConfigurationQueryHandler ConfigurationQueryHandler, ConfigurationCommandHandler configurationCommandHandler)
        {
            this.ConfigurationQueryHandler = ConfigurationQueryHandler;
            this.configurationCommandHandler = configurationCommandHandler;
        }


        [HttpGet, Route("")]
        public IHttpActionResult GetConfigurations()
        {
            var configuration = new GetConfigurationQuery();
            var configurations = ConfigurationQueryHandler.Handle(configuration);

            return Ok(new { Success = true, Data = configurations });
        }

        [HttpPut, Route("")]
        public IHttpActionResult Put(UpdateConfigurationCommand configuration)
        {
            configurationCommandHandler.Handle(configuration);
            return Ok(new { Success = true });
        }
    }

我的回复: get response configuration

我的回复: put response configuration

我想要返回响应状态码200,但我的响应会返回状态码500.

0 个答案:

没有答案