Chr*_*sgh 11 c# asp.net asp.net-web-api
我需要为ASP.NET Web API生成绝对URL以用于以后的回调/重定向.
可以使用生成链接
Url.Link("RouteName", new { controller = "Controller", action = "Action" });
Run Code Online (Sandbox Code Playgroud)
这会返回正确的Url,但是,我需要它始终是https.Url.Link似乎使用当前请求的方案生成URL.例如,如果生成url的请求类似于http://www.myhost.com/controller/generateUrl,则Url.Link会生成一个http url.如果生成URL的请求是https://www.myhost.com/controller/generateUrl,则Url.Link会生成https网址.
需要始终使用https生成网址.是否有可以传递给Url.Link的参数或路由值来实现此目的?
谢谢.
Tri*_*isk 13
这似乎不可能 Url.Link()
我会检查HttpRequest并将其更改为https以使所有人Url.Link()返回https链接.
就像是:
if (Url.Request.RequestUri.Scheme != Uri.UriSchemeHttps)
{
var secureUrlBuilder = new UriBuilder(Url.Request.RequestUri);
secureUrlBuilder.Scheme = Uri.UriSchemeHttps;
Url.Request.RequestUri = new Uri(secureUrlBuilder.ToString());
}
// should now return https
Url.Link("RouteName", new { controller = "Controller", action = "Action" });
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9036 次 |
| 最近记录: |