使用Asp.Net 5 MVC 6控制器我正在移植Api控制器,似乎无法解决如何在控制器的操作中访问请求对象。
控制器示例:
[Microsoft.AspNet.Authorization.Authorize(Roles = "Admin,User")]
public class DataManagementController
{
[Microsoft.AspNet.Mvc.HttpPost]
public async Task<HttpResponseMessage> Prospects()
{
if (!Request.Content.IsMimeMultipartContent("form-data"))
{
throw new HttpResponseException(HttpStatusCode.BadRequest);
}
}
}
在abopve代码中,if条件中的请求未找到且VS resolve仅提供使用Microsoft.Net.Http.Server的beta版本
我错过了一些明显的东西吗?
答案 0 :(得分:3)
您需要继承Controller
;
using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Mvc;
using System.Net;
using System.Net.Http;
[Authorize(Roles = "Admin,User")]
public class DataManagementController : Controller // inherit
{
[HttpPost]
public HttpResponseMessage Prospects()
{
if (!HttpContext.Request.HasFormContentType)
return new HttpResponseMessage(HttpStatusCode.BadRequest);
return new HttpResponseMessage(HttpStatusCode.OK);
}
}