参考资料:https://sites.google.com/site/netcorenote/asp-net-core/get-scheme-url-host

Example there's an given url: http://localhost:4800/account/login

获取整个url地址:

在页面(cstml)中

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

在 Controller 中

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

获取请求的方式(scheme:http/https):http

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

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

获取域名(不带端口号)[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

C# 如何获取Url的host以及是否是http的更多相关文章

  1. js获取URL中的参数

    js获取URL中的一些参数的意思 location对象 含有当前URL的信息. 属性 href 整个URL字符串. protocol 含有URL第一部分的字符串,如http: host 包含有URL中 ...

  2. js获取url信息

    设置或获取对象指定的文件名或路径. alert(window.location.pathname) 设置或获取整个 URL 为字符串. alert(window.location.href); 设置或 ...

  3. js获取url的常用方法

    //设置或获取对象指定的文件名或路径. console.log(window.location.pathname) //设置或获取整个 URL 为字符串. console.log(window.loc ...

  4. js获取url方法

    //设置或获取对象指定的文件名或路径.alert(window.location.pathname); //设置或获取整个 URL 为字符串.alert(window.location.href); ...

  5. 一个用php实现的获取URL信息的类

    获取URL信息的类 使用这个类,你能获得URL的如下信息: - Host  - Path  - Statuscode (eg. 404,200, ...)  - HTTP Version  - Ser ...

  6. js获取url传递参数

    <head> <meta charset="UTF-8"> <title></title> <script type=&quo ...

  7. js获取url传递的参数

    获取URL带参数的JAVASCRIPT客户端解决方案 一.正则分析法.(我较喜欢使用正则)function GetQueryString(name) {var reg = new RegExp(“(^ ...

  8. javascript获取url信息的常见方法

    先以"http://www.cnblogs.com/wuxibolgs329/p/6188619.html#flag?test=12345"为例,然后获得它的各个组成部分. 1.获 ...

  9. JS获取url参数及url编码、解码

    完整的URL由这几个部分构成:scheme://host:port/path?query#fragment ,各部分的取法如下: window.location.href:获取完整url的方法:,即s ...

随机推荐

  1. css与html基础收集

    1.css去掉iPhone.iPad默认按钮样式 nput[type="button"], input[type="submit"], input[type=& ...

  2. boa调试

    Cannot access memory at address 0x0 0x400fc7e0 in ?? () 0 0x4014f0dc in wcscasecmp_l () from /lib/li ...

  3. 暴力求解Calculator:The Game

    本文详实的记录的我的思考过程,类似流水账.... 目前已经烂尾,我对付不了133关后面的关卡 这个手机游戏挺不错的,就是有点难,所以要写程序,暴力的通关. 游戏名字:Calculator:The Ga ...

  4. Swift 编程杂谈

    1.Swift 3.0 使用Cocopods 导入第三方报错 之前一直用Object-C 编写代码  用Cocopods导入第三方没出过什么问题(PS:2017最新cocoaPods安装教程) 今天用 ...

  5. 5 个免费的受欢迎的 SQLite 管理工具【申明:来源于网络】

    5 个免费的受欢迎的 SQLite 管理工具 包含内容: SQLite Expert – Personal Edition SQLite Expert 提供两个版本,分别是个人版和专业版.其中个人版是 ...

  6. json格式 (JavaScipt Object Notation)

    json格式 json语法规则: 01.对象表现形式 key:value 键值对 02.如果有多个数据,之间使用逗号隔开 k1:v1,k2:v2 03.把对象写在大括号中 var student={a ...

  7. 大数据与云计算的关系是什么,Hadoop又如何参与其中?Nosql在什么位置,与BI又有什么关系?

    大数据与云计算的关系是什么,Hadoop又如何参与其中,Nosql在什么位置,与BI又有什么关系?以下这篇文字讲他们的关系讲的非常清楚.  在谈大数据的时候,首先谈到的就是大数据的4V特性,即类型复杂 ...

  8. VsCode 使用专用编程字体FiraCode

    FiraCode资料:https://github.com/tonsky/FiraCode PHP代码效果如下: VsCode 配置中添加: "editor.fontFamily" ...

  9. [Swift]LeetCode43. 字符串相乘 | Multiply Strings

    Given two non-negative integers num1 and num2 represented as strings, return the product of num1and  ...

  10. [Swift]LeetCode994. 腐烂的橘子 | Rotting Oranges

    In a given grid, each cell can have one of three values: the value 0 representing an empty cell; the ...