C# 如何獲取Url的host以及是不是http

參考資料:https://sites.google.com/site/netcorenote/asp-net-core/get-scheme-url-hosthtml

Example there's an given url: http://localhost:4800/account/loginasp.net

獲取整個url地址:google

在頁面(cstml)中 url

Microsoft.AspNetCore.Http.Extensions.UriHelper.GetDisplayUrl(Context.Request);.net

在 Controller 中htm

Microsoft.AspNetCore.Http.Extensions.UriHelper.GetDisplayUrl(Request);get

獲取請求的方式(scheme:http/https):http域名

In asp.net 4.6 -> Request.Url.Schemeit

in .net core -> Context.Request.Scheme (cshtml) , in Controller -> Request.Schemeio

獲取域名(不帶端口號)[Get the host]:

In asp.net 4.6 -> Request.Url.Host

in .net core -> Context.Request.Host.Host (cshtml) , in Controller -> Request.Host.Host

獲取域名(帶端口號)[Get the host]: localhost:4800

In asp.net 4.6 ->

in .net core -> Context.Request.Host.Value (cshtml) , in Controller -> Request.Host.Value

獲取路徑(Get the path): /account/login

In asp.net 4.6:

In .net core: @Context.Request.Path (cshtml)

獲取端口號(Get port): 4800 (if a url contains port)

In asp.net 4.6: Request.Url.Port

In .net core: @Context.Request.Host.Port (cshtml) , in Controller -> Request.Host.Port

相關文章
相關標籤/搜索