webapi5.2.3如何使用302重定向?

时间:2018-07-16 03:50:46

标签: asp.net asp.net-web-api2

我的代码:

[Route("dish"), HttpGet]
public async Task<DishDto> ShowDish(int dishid)
{
    if (dishid > 100000)
    {
        HttpContext.Current.Response.Redirect("https://example.com/?dishid=" + dishid.ToString());
        HttpContext.Current.Response.End();
        return null;
    }
    // other method

但报告错误: 发送HTTP标头后,服务器无法设置状态。

我搜索并使用了此代码,但它对我没有帮助:

var response = Request.CreateResponse(System.Net.HttpStatusCode.Redirect);
response.Headers.Location = new Uri("https://example.com");
this.ActionContext.Response = response;

有人可以帮助我吗? 我的项目使用版本:webapi5.2.3

0 个答案:

没有答案