私の Application_Start で:
var jsonFormatter = new JsonMediaTypeFormatter();
config.Services.Replace(typeof(IContentNegotiator), new JsonContentNegotiator(jsonFormatter));
私のデフォルトの URL:
[HttpGet]
[Route("~/")]
public HttpResponseMessage Index()
{
var stream = File.OpenRead(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Views\Home\Index.html"));
var content = new StreamContent(stream);
return new HttpResponseMessage() { Content = content };
}
コンテンツはタイプです"text/html"
が、設定していませんがresponse.Headers.ContentType
、htmlコンテンツネゴシエーターのようなものはありませんが、htmlファイルは正しく返されますが、実際には、アクションがjsonとしてhtmlファイルを返すか、エラーが発生すると想定しましたが、すべてがうまくいきました。
何故ですか?