C# 如何获取Url的host以及是否是http
参考资料: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的更多相关文章
- js获取URL中的参数
js获取URL中的一些参数的意思 location对象 含有当前URL的信息. 属性 href 整个URL字符串. protocol 含有URL第一部分的字符串,如http: host 包含有URL中 ...
- js获取url信息
设置或获取对象指定的文件名或路径. alert(window.location.pathname) 设置或获取整个 URL 为字符串. alert(window.location.href); 设置或 ...
- js获取url的常用方法
//设置或获取对象指定的文件名或路径. console.log(window.location.pathname) //设置或获取整个 URL 为字符串. console.log(window.loc ...
- js获取url方法
//设置或获取对象指定的文件名或路径.alert(window.location.pathname); //设置或获取整个 URL 为字符串.alert(window.location.href); ...
- 一个用php实现的获取URL信息的类
获取URL信息的类 使用这个类,你能获得URL的如下信息: - Host - Path - Statuscode (eg. 404,200, ...) - HTTP Version - Ser ...
- js获取url传递参数
<head> <meta charset="UTF-8"> <title></title> <script type=&quo ...
- js获取url传递的参数
获取URL带参数的JAVASCRIPT客户端解决方案 一.正则分析法.(我较喜欢使用正则)function GetQueryString(name) {var reg = new RegExp(“(^ ...
- javascript获取url信息的常见方法
先以"http://www.cnblogs.com/wuxibolgs329/p/6188619.html#flag?test=12345"为例,然后获得它的各个组成部分. 1.获 ...
- JS获取url参数及url编码、解码
完整的URL由这几个部分构成:scheme://host:port/path?query#fragment ,各部分的取法如下: window.location.href:获取完整url的方法:,即s ...
随机推荐
- LeetCode 26 Remove Duplicates from Sorted Array [Array/std::distance/std::unique] <c++>
LeetCode 26 Remove Duplicates from Sorted Array [Array/std::distance/std::unique] <c++> 给出排序好的 ...
- RequireJS简单实用说明
OM前端框架说明 om前端框架采用RequireJS,RequireJS 是一个JavaScript模块加载器.它非常适合在浏览器中使用, 它非常适合在浏览器中使用,但它也可以用在其他脚本环境, 就 ...
- 用挂载,使用NTFS移动硬盘,拷贝iPhone里的照片,拷到MAC
2. 写权限挂载移动硬盘 1) mount查看 2) diskutil umount /dev/disk2 3) sudo mount_ntfs -o rw,nobrowse /dev/disk2s1 ...
- SecureCRT连接虚拟机失败及虚拟机ping不通外网
背景: VMware上安装了centos,从学校的网络换到了家里后,用SecureCRT登录时发现 connection closed,然后在虚拟机里发现ping不通外网了,ping虚拟机IP是通的. ...
- JAVA 热文
Java技术面试篇 Javase基础面试题(1) Javase基础面试题(2) Javase基础面试题(3) Javase基础面试题(4) Javase基础面试题(5) Javaweb面试题(6) J ...
- 测试连接失败,因为初始化提供程序时发生错误,[DBNMPNTW] ConnectionOpen (CreateFile())
此主题相关图片如下:错误.jpg 今天发布的程序,在其它电脑上运行没问题,就是其中一台电脑上运程报这个错.系统是Win7的查了好久,最后解决 方法如下: 在报错的电脑上,单击"开始" ...
- hadoop源码分析(2):Map-Reduce的过程解析
一.客户端 Map-Reduce的过程首先是由客户端提交一个任务开始的. 提交任务主要是通过JobClient.runJob(JobConf)静态函数实现的: public static Runnin ...
- [Swift]LeetCode34. 在排序数组中查找元素的第一个和最后一个位置 | Find First and Last Position of Element in Sorted Array
Given an array of integers nums sorted in ascending order, find the starting and ending position of ...
- [Swift]LeetCode450. 删除二叉搜索树中的节点 | Delete Node in a BST
Given a root node reference of a BST and a key, delete the node with the given key in the BST. Retur ...
- [Swift]LeetCode844. 比较含退格的字符串 | Backspace String Compare
Given two strings S and T, return if they are equal when both are typed into empty text editors. # m ...