[英]How do I pass data from an ASP.NET WebAPI ApiController to an ASP.NET MVC Controller?
假设我在ASP.NET Web API控制器中具有以下方法:
public HttpResponseMessage Get(string code1, string code2)
{
var response = new HttpResponseMessage(HttpStatusCode.Redirect);
response.Headers.Location = new Uri("/", UriKind.Relative);
return response;
}
我想接受传入的代码1和代码2的值,并将它们提供给MVC控制器(基于上面的重定向,我们假设它是HomeController)。 做这个的最好方式是什么?
一些注意事项:
谢谢!
更新:这是最终代码和方法的外观。
public async Task<HttpResponseMessage> Get(string display, string code)
{
var auth = new AuthenticationClient();
await auth.WebServer(_consumerKey, _consumerSecret, _callbackUrl, code);
var url = string.Format("/?token={0}&api={1}&instance_url={2}", auth.AccessToken, auth.ApiVersion,
auth.InstanceUrl);
var response = new HttpResponseMessage(HttpStatusCode.Redirect);
response.Headers.Location = new Uri(url, UriKind.Relative);
return response;
}
除了使用查询字符串参数外,不确定是否还有其他选择。 路径参数实际上没有多大意义,因为没有带有身份验证令牌的自然层次结构。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.