1.获取完整网址URL

方法一:先引用“using Microsoft.AspNetCore.Http.Extensions;”,然后直接用“Request.GetDisplayUrl();”

方法二:后来参考 Microsoft.AspNetCore.Rewrite 的源代码,写了一个扩展方法实现

namespace Microsoft.AspNetCore.Http
{
public static class HttpRequestExtensions
{
public static string GetAbsoluteUri(this HttpRequest request)
{
return new StringBuilder()
.Append(request.Scheme)
.Append("://")
.Append(request.Host)
.Append(request.PathBase)
.Append(request.Path)
.Append(request.QueryString)
.ToString();
}
}
}

2.获取网站在服务器的物理路径

    public class HomeController : Controller
{
IHostingEnvironment env;
public HomeController(IHostingEnvironment _env) { env = _env; } public IActionResult Index()
{
//https://localhost:44359/home/index
string url = HttpContext.Request.GetDisplayUrl(); //D:\\Visual Studio 2017\\tourism_app\\ZhiRen.Tourism.UI\\bin\\Debug\\netcoreapp2.1\\
string path = System.AppContext.BaseDirectory; //D:\\Visual Studio 2017\\tourism_app\\ZhiRen.Tourism.UI
string siteRoot = env.ContentRootPath; //D:\\Visual Studio 2017\\tourism_app\\ZhiRen.Tourism.UI\\wwwroot
string wwwroot = env.WebRootPath; //D:\\Visual Studio 2017\\tourism_app\\ZhiRen.Tourism.UI\\bin\\Debug\\netcoreapp2.1
var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location); return View();
}
}

  

asp.net core 中的各种路径的更多相关文章

  1. 在Asp.Net Core中取得物理路径

    在Asp.Net Core中取得物理路径: 从ASP.NET Core RC2开始,可以通过注入 IHostingEnvironment 服务对象来取得Web根目录和内容根目录的物理路径,如下所示: ...

  2. Asp.Net Core 中获取应用程序物理路径(Getting the Web Root Path and the Content Root Path in ASP.NET Core)

    如果要得到传统的ASP.Net应用程序中的相对路径或虚拟路径对应的服务器物理路径,只需要使用使用Server.MapPath()方法来取得Asp.Net根目录的物理路径,如下所示: // Classi ...

  3. ASP.NET Core 中的SEO优化(4):自定义视图路径及主题切换

    系列回顾 <ASP.NET Core 中的SEO优化(1):中间件实现服务端静态化缓存> <ASP.NET Core 中的SEO优化(2):中间件中渲染Razor视图> < ...

  4. 在ASP.NET Core中使用百度在线编辑器UEditor

    在ASP.NET Core中使用百度在线编辑器UEditor 0x00 起因 最近需要一个在线编辑器,之前听人说过百度的UEditor不错,去官网下了一个.不过服务端只有ASP.NET版的,如果是为了 ...

  5. ASP.NET Core 中文文档 第三章 原理(6)全球化与本地化

    原文:Globalization and localization 作者:Rick Anderson.Damien Bowden.Bart Calixto.Nadeem Afana 翻译:谢炀(Kil ...

  6. ASP.NET Core 中文文档 第三章 原理(13)管理应用程序状态

    原文:Managing Application State 作者:Steve Smith 翻译:姚阿勇(Dr.Yao) 校对:高嵩 在 ASP.NET Core 中,有多种途径可以对应用程序的状态进行 ...

  7. 如何在ASP.NET Core中实现CORS跨域

    注:下载本文的完整代码示例请访问 > How to enable CORS(Cross-origin resource sharing) in ASP.NET Core 如何在ASP.NET C ...

  8. 在ASP.NET Core中怎么使用HttpContext.Current

    一.前言 我们都知道,ASP.NET Core作为最新的框架,在MVC5和ASP.NET WebForm的基础上做了大量的重构.如果我们想使用以前版本中的HttpContext.Current的话,目 ...

  9. ASP.NET Core中使用Razor视图引擎渲染视图为字符串

    一.前言 在有些项目需求上或许需要根据模板生产静态页面,那么你一样可以用Razor语法去直接解析你的页面从而把解析的页面生成静态页,这样的使用场景很多,不限于生成静态页面,视图引擎为我们提供了模型到视 ...

随机推荐

  1. Towards Evaluating the Robustness of Neural Networks

    目录 概 主要内容 基本的概念 目标函数 如何选择c 如何应对Box约束 attack attack attack Nicholas Carlini, David Wagner, Towards Ev ...

  2. Proximal Algorithms 6 Evaluating Proximal Operators

    目录 一般方法 二次函数 平滑函数 标量函数 一般的标量函数 多边形 对偶 仿射集合 半平面 Box Simplex Cones 二阶锥 半正定锥 指数锥 Pointwise maximum and ...

  3. pandas tutorial

    目录 Series 利用dict来创建series 利用标量创建series 取 Dataframe 利用dict创建dataframe 选择 添加列 列移除 行的选择, 添加, 移除 Panel B ...

  4. 集合不安全之 ArrayList及其三种解决方案【CopyOnWriteArrayList 、synchronizedList、Vector 】

    @ 目录 一.前言 二.为什么线程不安全 三.解决方案一CopyOnWriteArrayList (推荐,读多写少场景) 四.Collections.synchronizedList(加锁) 五.Ve ...

  5. 初识python: flush 实现进度条打印

    通过flush(强制刷新)实现,类似进度条打印: #!/user/bin env python # author:Simple-Sir # time:20180918 #打印进度条 import sy ...

  6. jsp使用${}语法,对应的spring后台使用Model

    实现的前提,一定要在jsp文件顶部加上 <%@page isELIgnored="false" %> 如上图${aa}与${bb},是直接使用Model的key值对应的 ...

  7. spring boot + redis --- 心得

    1.前言 习惯使用springMVC 配置 redis ,现在使用spring boot ,得好好总结怎么在spring boot 配置和使用 ,区别真的挺大的. 2.环境 spring boot  ...

  8. react中prop-types的使用

    什么是prop-types?prop代表父组件传递过来的值,types代表类型.简单来说就是用来校验父组件传递过来值的类型 import PropTypes from 'prop-types'; To ...

  9. react将HTML字符串解析为HTML标签

    当后台返回的数据是字符串html的话,我们可以利用dangerouslySetInnerHTML属性来把字符串转换成html标签 function showhtml(htmlString){ var ...

  10. vue-cli axios封装(element-ui)

    1.http.js /** * * http配置 */ import axios from 'axios'import { Loading, Message } from 'element-ui' / ...