【问题标题】:Get current domain in ASMX在 ASMX 中获取当前域
【发布时间】:2010-08-04 09:39:41
【问题描述】:

在 asmx Web 服务的 C# 中,如何获取调用该 Web 服务的当前域? HttpContext.Current.Request.Url.Host 返回我想要的那种,但我只需要http://mydomain.com 而不是http://mydomain.com/Folder/Mywebservice.asmx。 我知道我可以剪断那根绳子,但它看起来真的很不优雅。 谢谢

【问题讨论】:

标签: c# web-services asmx


【解决方案1】:

Uri.GetLeftPart 在这里提供帮助:

Request.Url.GetLeftPart(UriPartial.Authority)

【讨论】:

    【解决方案2】:

    在VB.Net中我用过...

    With HttpContext.Current.Request.Url
        sDomain=.Scheme & System.Uri.SchemeDelimiter & .Host
    End With
    

    或者,如果您关心端口,那么...

    With HttpContext.Current.Request.Url
        sDomain=.Scheme & System.Uri.SchemeDelimiter & .Host & IIf(.IsDefaultPort,"",":") & .Port
    End With
    

    应该很容易转换为 C# ;)

    【讨论】:

      猜你喜欢
      • 2012-05-29
      • 1970-01-01
      • 1970-01-01
      • 2014-11-29
      • 2016-12-01
      • 2017-02-22
      • 1970-01-01
      • 1970-01-01
      • 2019-08-17
      相关资源
      最近更新 更多