asp.net-web-api – 从ASP.NET Web API ASP.NET Core 2返回HTML并获取ht
发布时间:2020-08-16 08:02:31 所属栏目:asp.Net 来源:互联网
导读:这是 Return HTML from ASP.NET Web API的后续行动. 我按照说明操作,但我在浏览器中收到错误406. 我的代码: [Produces(text/html)] [Route(api/[controller])] public class AboutController : Controller { [HttpGet]
这是 Return HTML from ASP.NET Web API的后续行动. 我按照说明操作,但我在浏览器中收到错误406. [Produces("text/html")] [Route("api/[controller]")] public class AboutController : Controller { [HttpGet] public string Get() { return "<html><body>Welcome</body></html>"; } ... 而且,简单地说: public void ConfigureServices(IServiceCollection services) { services.AddMvc(); } 当我删除Produces行时,我得到纯文本< html>< body>欢迎< / body>< / html>在浏览器中(没有错误). 我错过了什么?谢谢. 解决方法正如 KTCO指出 here:
解决方案是: [HttpGet] public ContentResult Get() { return new ContentResult { ContentType = "text/html",StatusCode = (int) HttpStatusCode.OK,Content = "<html><body>Welcome</body></html>" }; } 无需更改AddMvc(当然也没有Produce属性). 我希望这可以帮助别人. (编辑:鄂州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 所有我使用IO的动作都是异步的?
- asp.net core webapi 服务端配置跨域的实例
- asp.net-mvc – 如何组合两个dataTextFields的SelectList描
- remoting和webservice有什么区别
- asp.net-core – ClaimTypes的ASP.NET要求
- 将mvc 5应用程序连接到Azure中的ACS?
- asp.net 结合mysql存储过程进行分页代码
- VS 2015.为ASP.NET 5 web项目设置正确的目标框架
- asp.net – 将url参数添加到asp主题文件夹中的css文件中
- asp.net-mvc – ie9:调试时出现恼人的弹出:“错误:’__f
推荐文章
站长推荐
热点阅读