参考资料: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. swust oj 1016

    插入排序算法实现 1000(ms) 10000(kb) 2613 / 6080 插入排序算法实现. 输入 第一行是待排序数据元素的个数: 第二行是待排序的数据元素. 输出 一趟直接插入排序算法结果. ...

  2. 玩转vue前进刷新,后退不刷新and按需刷新

    大白萝卜小课堂开讲了!带你玩转vue前进后退按需刷新! 用vue做后台管理项目,特别是有列表页.列表数据详情页.列表数据修改页功能的码友们,几乎都被vue前进后退都刷新的逻辑坑过,本萝卜更是! 萝卜的 ...

  3. 实战深度学习OpenCV(一):canny边缘检测

    利用canny边缘检测,我们可以很好地得到哦一个图像的轮廓,下面是基于C++的,这是我们通过这段代码得到的结果: #include "pch.h" #include <ios ...

  4. ReactNative问题随记1 Exception in thread "main" java.lang.RuntimeException: gradle-2.14.1-all.zip

    ReactNative问题随记 想运行在真机上,在运行命令react-native run-android遇到错误如下: Scanning 559 folders for symlinks in D: ...

  5. Python爬虫5-利用usergent伪装访问方式

    GitHub代码练习地址:https://github.com/Neo-ML/PythonPractice/blob/master/SpiderPrac08_useragent.py UserAgen ...

  6. 配置Zookeeper、Dubbox

    CentOS的配置: 1.给CentOS安装Zookeeper: 网络配置成仅主机 上传tar.gz:比如用FTP tar -xvzf ... cd zookeeper mkdir data cd c ...

  7. [Swift]LeetCode398. 随机数索引 | Random Pick Index

    Given an array of integers with possible duplicates, randomly output the index of a given target num ...

  8. [SQL]LeetCode577.员工奖金 | Employee Bonus

    Select all employee's name and bonus whose bonus is < 1000. Table:Employee +-------+--------+---- ...

  9. [Swift]LeetCode677. 键值映射 | Map Sum Pairs

    Implement a MapSum class with insert, and sum methods. For the method insert, you'll be given a pair ...

  10. [Swift]LeetCode859. 亲密字符串 | Buddy Strings

    Given two strings A and B of lowercase letters, return true if and only if we can swap two letters i ...