【问题标题】:Asp Net c# get full host with cname?Asp Net c# 使用 cname 获取完整主机?
【发布时间】:2021-01-27 12:01:22
【问题描述】:

如何获取配置了 cname 的站点的完整主机或完整 URL?

例如,我有一个网址为http://shop.gv.com的网站。

使用 cname 我得到一个类似http://en.shop.gv.com 的网站

当我使用 System.Web.HttpContext.Current.Request.Url.Host 时,我只得到http://shop.gv.com

我怎样才能得到完整的? 如果我使用 JavaScript 函数 window.location.hostname,我可以工作。

【问题讨论】:

    标签: c#


    【解决方案1】:

    使用System.Web.HttpContext.Current.Request.RawUrl 获取完整路径 或者您可以参考此链接以获取更好的方法sub domain

    【讨论】:

    • 谢谢,但我需要 url 中显示的域。使用 javascript 函数 (window.location.hostname) 我得到 en.shop.gv.com 但使用 request.url.host 我只得到 shop.gv.com ,缺少“en”部分
    • 检查我在答案中提到的链接,
    猜你喜欢
    • 2016-09-02
    • 1970-01-01
    • 1970-01-01
    • 2020-09-25
    • 1970-01-01
    • 1970-01-01
    • 2011-01-11
    • 2017-05-11
    • 1970-01-01
    相关资源
    最近更新 更多