C# 无法从控制器返回HTML
我的代码无法从控制器返回HTML。浏览器返回HTTP错误500-“此页面不工作” 控制器是用.net core 3.1编写的。代码如下:C# 无法从控制器返回HTML,c#,asp.net-core,C#,Asp.net Core,我的代码无法从控制器返回HTML。浏览器返回HTTP错误500-“此页面不工作” 控制器是用.net core 3.1编写的。代码如下: [ApiController] [Route("")] public class MyController : ControllerBase { [HttpGet] public async Task<ActionResult<ContentResult>> GetInformation()
[ApiController]
[Route("")]
public class MyController : ControllerBase
{
[HttpGet]
public async Task<ActionResult<ContentResult>> GetInformation()
{
string s = @"<!DOCTYPE html><html><head><title>.....";
return base.Content(s, "text/html");
}
}
如果愿意,还可以指定实现IActionResult
的ContentResult
:
public async Task<ContentResult> GetInformation()
public异步任务GetInformation()
IActionResult
允许操作在不同情况下返回不同的响应,例如使用BadRequest
、Content
或Ok
public async Task<ActionResult<ContentResult>> GetInformation()
public async Task<IActionResult> GetInformation()
public async Task<ContentResult> GetInformation()