我有一个可以重定向的 webapi Controller :
var response = this.Request.CreateResponse(HttpStatusCode.Redirect);
response.Headers.Add("Location",
"https://www.dropbox.com/1/oauth/authorize?oauth_token=" + pars["oauth_token"]
+ "&oauth_callback=http://localhost:2638/index.html#/tasks/compose-task/");
return response;
并从 javascript 调用它:
$.ajax("/api/dropbox/get_request_token", { dataType: 'json' })
.done(function (data)
{
alert(ko.toJSON(data));
})
.fail(function (err) {alert(ko.toJSON(err));});
网络选项卡显示:
GET http://localhost:2638/api/dropbox/get_request_token HTTP/1.1
Accept: application/json, text/javascript, */*; q=0.01
Referer: http://localhost:2638/
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.20 (KHTML, like Gecko) Chrome/25.0.1337.0 Safari/537.20
但它永远不会重定向到 dropbox.com。相反,它最终会失败()。
我错过了什么吗?
最佳答案
“位置” header 已有一个属性。尝试:
response.Headers.Location = new Uri( "http://google.com");
这对我有用。
关于javascript - 无法重定向以在 Asp.net WebApi 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13669673/