[英]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.