如何在ASPNET网络API重定向 [英] How to Redirect in ASPNET Web API
本文介绍了如何在ASPNET网络API重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个Web API相当于MVC控制器方法RedirectToAction控制器的方法?我想从另一个调用一种方法,但保留筛选器操作的辅助方法。
解决方案
有一个Web API相当于MVC控制器方法RedirectToAction控制器的方法?
块引用>您可以设置Location头:
公开的Htt presponseMessage的get()
{
VAR响应= Request.CreateResponse(的HTTPStatus code.Found);
response.Headers.Location =新的URI(http://www.google.com);
返回响应;
}Is there a Web API controller method equivalent to the MVC controller method RedirectToAction? I would like to call one method from another, but retain the filter actions for the secondary method.
解决方案Is there a Web API controller method equivalent to the MVC controller method RedirectToAction?
You could set the Location header:
public HttpResponseMessage Get() { var response = Request.CreateResponse(HttpStatusCode.Found); response.Headers.Location = new Uri("http://www.google.com"); return response; }
这篇关于如何在ASPNET网络API重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文