0

我在控制器上创建回调方法。我对社交提供者使用 Oauth 授权。当我为回调创建 url 并为提供者发送查询时 - 提供者正在获取下一个 url:

http://127.0.0.1:8080/OAuth/CallBack

但是在这种情况下这个域 - http://simple.com

如何使用当前上下文和这个域?在调试模式下,项目工作正常,因为项目名称与本地地址匹配。

var helper = new UrlHelper(requestContext);
var actionCallback = helper.Action("CallBack", "OAuth", null, "http");
4

2 回答 2

0

我的意思是这个。谢谢,我已经解决了这个问题。

 public Uri GetUri(Controller.HttpContext.Request request){
    var request = Controller.HttpContext.Request;
    string uriStr = "";

    uriStr = String.Format("{0}", request.GetApplicationAbsoluteUrl);

    // bad variant! but is some fix-stub
    return new Uri(uriStr+"OAuth/Callback");
}

public static string GetApplicationAbsoluteUrl(this HttpRequestBase request) {
    string forwardedHost;
    string appPath = request.ApplicationPath ?? String.Empty;

    if (appPath.Length > 0 && appPath[appPath.Length - 1] != '/')
        appPath += '/';

    var authority = request.Url.Host == "127.0.0.1" && (forwardedHost = request.Headers["X-Forwarded-Host"]) != null
                  ? forwardedHost
                  : request.Url.Authority;

    return String.Format("{0}://{1}{2}", request.Url.Scheme, authority, appPath);
}
于 2013-10-30T06:51:46.970 回答
0

这对我有用

UrlHelper url = new UrlHelper(HttpContext.Current.Request.RequestContext);
var actionCallback = url.Action("CallBack"); 
于 2013-10-28T17:03:37.133 回答