C#:返回带有http/https前缀的当前web路径

C#:返回带有http/https前缀的当前web路径,c#,asp.net-mvc,httpcontext,C#,Asp.net Mvc,Httpcontext,当使用HttpContext.Current.Request.Url.Authority时,我可以得到当前的主机站点,例如:localhost:8084 是否可以获取“完整”主机名,如:“” 对于某些实现,它将是http,而其他将是https,我需要根据站点地址创建URL。您可以使用HttpContext.Current.Request.IsSecureConnection检查http或https 另外请注意,使用HttpContext.Current.Request.Url.Scheme和Ht

当使用
HttpContext.Current.Request.Url.Authority时,我可以得到当前的主机站点,例如:localhost:8084

是否可以获取“完整”主机名,如:“”


对于某些实现,它将是http,而其他将是https,我需要根据站点地址创建URL。

您可以使用
HttpContext.Current.Request.IsSecureConnection
检查http或https


另外请注意,使用
HttpContext.Current.Request.Url.Scheme
HttpContext.Current.Request.Url.Host
可以提取该信息。

Url
返回什么?HttpContext.Current.Request.Url.Host注意本地调试环境和生产环境之间的差异,在生产环境中,您将获得http或https以及主机名