[英]UriHelper how to get production url path
var displayUrl = UriHelper.GetDisplayUrl(Request);
var urlBuilder = new UriBuilder(displayUrl) { Query = null, Fragment = null };
string _activation_url = urlBuilder.ToString().Substring(0, urlBuilder.ToString().LastIndexOf("/")) +"/this_is_my_link.html";
I expect to get correct uri production path, but I still get 我希望获得正确的uri生产路径,但我仍然可以
http://localhost:5000/api/mdc/this_is_my_link.html HTTP://本地主机:5000 / API / MDC / this_is_my_link.html
I deployed this on centos 7 我在centos 7上部署了这个
please help me.. 请帮我..
Thanks 谢谢
Don 唐
on asp core use 在asp核心上使用
absoluteUri = string.Concat(
request.Scheme,
"://",
request.Host.ToUriComponent(),
request.PathBase.ToUriComponent(),
request.Path.ToUriComponent(),
request.QueryString.ToUriComponent());
or you may choose either Getting absolute URLs using ASP.NET Core 或者您可以选择使用ASP.NET Core获取绝对URL
If you are using a reverse proxy, you should read this guide from Microsoft. 如果使用反向代理,则应阅读Microsoft的本指南 。
Essentially, your reverse proxy should provide these headers to your ASP.NET Core Application: 本质上,反向代理应将以下标头提供给ASP.NET Core应用程序:
X-Forwarded-For
- The client IP X-Forwarded-For
客户端IP X-Forwarded-Host
- The Host
header from the client (eg www.example.com:80
) X-Forwarded-Host
来自客户端的Host
标头(例如www.example.com:80
) X-Forwarded-Proto
- The protocl (eg HTTPS
) X-Forwarded-Proto
Proto-协议(例如HTTPS
) Then you need to configure your ASP.NET Core application to accept them. 然后,您需要配置ASP.NET Core应用程序以接受它们。 You can do so by calling the app.UseForwardedHeaders() method in your Startup's Configure
method. 您可以通过在Startup的Configure
方法中调用app.UseForwardedHeaders()方法来实现。
By default (if I'm reading the docs correctly) UseForwardedHeaders
(called as above) will accept X-Forwarded-For
and X-Forwarded-Proto
from a localhost
reverse proxy. 默认情况下 (如果我正确阅读了文档) UseForwardedHeaders
(如上所述)将接受来自localhost
反向代理的X-Forwarded-For
和X-Forwarded-Proto
。
If your situation is more complicated than that, you must configure the headers you want/the trusted reverse proxies: 如果您的情况比这更复杂,则必须配置所需的标头/受信任的反向代理:
var forwardedOptions = new ForwardedHeadersOptions()
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedHost | ForwardedHeaders.XForwardedProto // allow for, host, and proto (ForwardedHeaders.All also works here)
};
// if it's a single IP or a set of IPs but not a whole subnet
forwardedOptions.KnownProxies.Add(IPAddress.Parse("192.168.0.5"));
// if it's a whole subnet
forwardedOptions.KnownNetworks.Add(new IPNetwork("192.168.0.1", 24)); // 192.168.0.1 - 192.168.0.254
app.UseForwardedHeaders(forwardedOptions);
Also note that, depending on the reverse proxy you use, you might need to configure this on the reverse proxy 还要注意,根据您使用的反向代理,您可能需要在反向代理上进行配置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.