【发布时间】:2020-12-01 05:21:27
【问题描述】:
我正在使用 API 在 Asp.Net Core 中开发一个 Web 应用程序。我遇到了一个问题,即我无法通过 API 将 HTML 文件加载到 Web 应用程序中。我尝试通过以下方式加载 HTML
var fileContents = File.ReadAllText(HttpContext.Current.Server.MapPath("~/Content/HelloWorld.html"));
var response = new HttpResponseMessage();
response.Content = new StringContent(fileContents.ToString());
response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
return response;
在 API 控制器中但没有成功。 HTML 文件位于带有支持 css 文件的外部目录中。 谁能帮我将文件加载到浏览器中。
【问题讨论】:
标签: html api asp.net-core asp.net-core-webapi