在我的 Application_Start 中:
var jsonFormatter = new JsonMediaTypeFormatter();
config.Services.Replace(typeof(IContentNegotiator), new JsonContentNegotiator(jsonFormatter));
我的默认网址:
[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 内容协商器之类的东西,实际上我假设该操作会将 html 文件作为 json 返回,否则会发生错误但一切正常。
这是为什么?