zoukankan      html  css  js  c++  java
  • asp.net core 中的各种路径

    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();
            }
        }
    

      

  • 相关阅读:
    HWOJ之纠结的优化
    java中的对象数组
    短路特性的运用
    归并排序
    两个有序数列的合并
    java中的注释规范
    堆排序
    堆的建立
    希尔排序
    直接插入排序
  • 原文地址:https://www.cnblogs.com/fireicesion/p/10915278.html
Copyright © 2011-2022 走看看