私はこれに2日間苦労しています。それはとても落胆します。
これは比較的単純な API コントローラーです。
[HttpPost]
public HttpResponseMessage Save(ReportCreateInputModel model)
{
if (ModelState.IsValid)
{
_service.AddReport(model);
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, model);
return response;
}
else
{
return Request.CreateResponse(HttpStatusCode.BadRequest);
}
}
localhost:xxxx でデバッグすると、すべて正常に動作します。モデルは有効で、新しいレコードをデータベースに挿入できます。
しかし、サーバーに公開されると、常に400: Bad Request
. 別のブラウザを試してみましたが、サーバー側の問題であると確信しています。
次に、他の投稿で述べたように、リクエスト サイズを増やしてみました。しかし、それでもうまくいきません。そのサーバーにリモート デバッグ ツールをインストールできませんでした。
誰もこの問題を見たことがありますか?それはIIS 6で何かありますか?
どんな援助でも本当に感謝します。ありがとうございました!
アップデート:
Bad Request
エラーがスローされる前に api POST アクションがヒットすることはありません。しかし、なぜローカル デバッグで問題ないのでしょうか。
アップデート:
これらのコード行を WebApiConfig.cs に追加しました
var json = config.Formatters.JsonFormatter;
json.SerializerSettings.PreserveReferencesHandling =
Newtonsoft.Json.PreserveReferencesHandling.Objects;
json.SerializerSettings.ReferenceLoopHandling =
Newtonsoft.Json.ReferenceLoopHandling.Ignore;
config.Formatters.Remove(config.Formatters.XmlFormatter);
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
今、jqXHR.responseText
私には例外があります
"$id":"3","Message":"An error has occurred.",
"ExceptionMessage":"This operation requires IIS integrated pipeline mode.",
"ExceptionType":"System.PlatformNotSupportedException",
"StackTrace":" at System.Web.HttpContext.get_CurrentNotification()
at System.Web.HttpContextWrapper.get_CurrentNotification()
at GetCurrentNotification(Object )
at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target)"
わお!私が使用しているIIS 6と関係がありますか? その StackTrace が何であるかを誰が教えてくれますか? ありがとう。
ここget_CurrentNotification
で、IIS7 にのみ存在するパイプラインが必要であることがわかりました。しかし、私がどこに電話をかけたかを誰が教えてくれHttpContext.CurrentNotification
ますか?