使用自定义域名获取当前路径名

huangapple go评论70阅读模式
英文:

Using custom domain name getting current path name

问题

不要返回URL,而是返回自定义域名空间。

使用JavaScript和C#。

可以使用浏览器的开发者选项或使用Fiddler来查看。

类似于:

HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Host + "/SignUp/"

英文:

It should not return the URL like http://something.azurewebsites.net/signup instead custom domain name space.

with JavaScript and C# as well.

able to see using developer options of the browser or using fiddler.

something like

HttpContext.Current.Request.Url.Scheme+"://"+HttpContext.Current.Request.Url.Host+"/SignUp/"

答案1

得分: 0

  1. 使用自定义域名获取当前路径名称。
  2. 使用 System.IO.Path.GetFullPath 方法获取当前执行程序集的完整路径。
  3. 使用 System.Reflection.Assembly.GetExecutingAssembly().Location 获取当前执行程序集的位置。
  4. 结合自定义域名和当前路径以获取完整路径。

要使用 JavaScript 获取域空间名称的路径名称,可以使用 window.location.hostname

'window.location.hostname` 如果不需要 `port`(例如 `http://localhost:8080/`,`window.location.host = 'localhost:8080'` 和 `window.location.hostname = 'localhost'`
string str = HttpContext.Current.Request.Url.PathAndQuery;
string strUrl = HttpContext.Current.Request.Url.AbsoluteUri.Replace(str, "/");
string customDomain = "https://www.something.com/";

string currentPath = System.IO.Path.GetFullPath(System.Reflection.Assembly.GetExecutingAssembly().Location);
string combinedPath = customDomain + currentPath;

Console.WriteLine("合并后的路径是:" + combinedPath);

引用来源于 MDN Web Docs

英文:

>Using custom domain name getting current path name.

  1. System.IO.Path.GetFullPath method to get the full path of the current executing assembly.

  2. System.Reflection.Assembly.GetExecutingAssembly().Location -To get the location of the current executing assembly.

  3. And combining the custom domain and the current path to get the complete path.

To fetch the path name for the domain space names with JavaScript you can use

window.location.hostname

'window.location.hostname` if you dont want the `port` (like `http://localhost:8080/`, `window.location.host = 'localhost:8080'` and `window.location.hostname = 'localhost`
string str = HttpContext.Current.Request.Url.PathAndQuery;
string strUrl = HttpContext.Current.Request.Url.AbsoluteUri.Replace(str, "/");
string customDomain = "https://www.something.com/";

string currentPath = System.IO.Path.GetFullPath(System.Reflection.Assembly.GetExecutingAssembly().Location);
string combinedPath = customDomain + currentPath;

Console.WriteLine("The combined pah is: " + combinedPath);

Reference taken from
MDN Web Docs

答案2

得分: 0

看起来你在使用 Azure Web App 时遇到了问题,URL 返回的是 Azure Web App 的 URL,而不是自定义域名。

要在 C# 中获取当前路径名称,你可以使用 HttpContext.Current.Request.Url 属性来获取当前请求的 URL。

然后,你可以使用 Scheme、Host 和 Path 属性来构建你想要的 URL。

string url = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Host + "/SignUp/";

在 JavaScript 中,你可以使用 window.location 对象来获取当前页面的 URL。然后,你可以使用 protocol、host 和 pathname 属性来构建你想要的 URL。

var url = window.location.protocol + "//" + window.location.host + "/SignUp/";

你还可以尝试使用 Azure Front Door 来将流量路由到 Azure Web App。Azure Front Door 允许你配置自定义域名和 URL 路径,可以帮助你实现所需的 URL 格式。Azure Front Door 允许你配置自定义域名 和 URL 路径,这可以帮助你实现所需的 URL 格式。

或者你可以使用 Azure Application Gateway 来重写 URL。根据文档,你可以创建一个重写规则,该规则会评估位置标头是否与特定模式匹配,然后将位置标头重写为不同的值。2

英文:

It seems like you are having issue with the URL being returned from your Azure Web App. The URL is returning the Azure Web App URL instead of the custom domain name.

To get the current path name using C#, you can use the HttpContext.Current.Request.Url property to get the URL of the current request.

You can then use the Scheme, Host, and Path properties to construct the URL you want.

string url = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Host + "/SignUp/";

In JavaScript, you can use the window.location object to get the URL of the current page. You can then use the protocol, host, and pathname properties to construct the URL you want.

var url = window.location.protocol + "//" + window.location.host + "/SignUp/";

You may also try using Azure Front Door to route traffic to your Azure Web App. Azure Front Door allows you to configure custom domains and URL paths, which can help you achieve the desired URL format.

Or Azure Application Gateway to rewrite the URL.
According to the documentation, you can create a rewrite rule with a condition that evaluates if the location header matches a specific pattern, and then rewrite the location header to a different value.

huangapple
  • 本文由 发表于 2023年2月10日 15:35:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75408124.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定