[英]How do I pass data from an ASP.NET WebAPI ApiController to an ASP.NET MVC Controller?
Let's say I have the following method in my ASP.NET Web API 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;
}
I'd like to take the values passed in for code1 and code2 and make them available to an MVC Controller (based on the redirect above, let's just assume it's the HomeController). 我想接受传入的代码1和代码2的值,并将它们提供给MVC控制器(基于上面的重定向,我们假设它是HomeController)。 What is the best way to do this?
做这个的最好方式是什么?
A few considerations: 一些注意事项:
Thanks! 谢谢!
Update: Here's a look at the final code and approach. 更新:这是最终代码和方法的外观。
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;
}
Not sure you have much choice other than to use a query string parameter. 除了使用查询字符串参数外,不确定是否还有其他选择。 Path parameters don't really make much sense as there is no natural hierarchy with an auth token.
路径参数实际上没有多大意义,因为没有带有身份验证令牌的自然层次结构。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.