<bdo id='e9MaI'></bdo><ul id='e9MaI'></ul>

<legend id='e9MaI'><style id='e9MaI'><dir id='e9MaI'><q id='e9MaI'></q></dir></style></legend>

      1. <small id='e9MaI'></small><noframes id='e9MaI'>

        <tfoot id='e9MaI'></tfoot>

      2. <i id='e9MaI'><tr id='e9MaI'><dt id='e9MaI'><q id='e9MaI'><span id='e9MaI'><b id='e9MaI'><form id='e9MaI'><ins id='e9MaI'></ins><ul id='e9MaI'></ul><sub id='e9MaI'></sub></form><legend id='e9MaI'></legend><bdo id='e9MaI'><pre id='e9MaI'><center id='e9MaI'></center></pre></bdo></b><th id='e9MaI'></th></span></q></dt></tr></i><div id='e9MaI'><tfoot id='e9MaI'></tfoot><dl id='e9MaI'><fieldset id='e9MaI'></fieldset></dl></div>
      3. ASP.NET Core 中的 Server.MapPath 等价物是什么?

        What is the equivalent of Server.MapPath in ASP.NET Core?(ASP.NET Core 中的 Server.MapPath 等价物是什么?)
            <bdo id='TNczT'></bdo><ul id='TNczT'></ul>

              <legend id='TNczT'><style id='TNczT'><dir id='TNczT'><q id='TNczT'></q></dir></style></legend>
            1. <small id='TNczT'></small><noframes id='TNczT'>

                <tbody id='TNczT'></tbody>

              <i id='TNczT'><tr id='TNczT'><dt id='TNczT'><q id='TNczT'><span id='TNczT'><b id='TNczT'><form id='TNczT'><ins id='TNczT'></ins><ul id='TNczT'></ul><sub id='TNczT'></sub></form><legend id='TNczT'></legend><bdo id='TNczT'><pre id='TNczT'><center id='TNczT'></center></pre></bdo></b><th id='TNczT'></th></span></q></dt></tr></i><div id='TNczT'><tfoot id='TNczT'></tfoot><dl id='TNczT'><fieldset id='TNczT'></fieldset></dl></div>

            2. <tfoot id='TNczT'></tfoot>

                1. 本文介绍了ASP.NET Core 中的 Server.MapPath 等价物是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想复制到我的控制器中的一些代码中有这一行,但编译器抱怨

                  I have this line in some code I want to copy into my controller, but the compiler complains that

                  名称服务器"在当前上下文中不存在

                  The name 'Server' does not exist in the current context

                  var UploadPath = Server.MapPath("~/App_Data/uploads")
                  

                  如何在 ASP.NET Core 中实现等效?

                  How can I achieve the equivalent in ASP.NET Core?

                  推荐答案

                  更新:IHostingEnvironment 已弃用.请参阅下面的更新.

                  在 Asp.NET Core 2.2 及以下版本中,托管环境已使用接口进行抽象,IHostingEnvironment

                  In Asp.NET Core 2.2 and below, the hosting environment has been abstracted using the interface, IHostingEnvironment

                  ContentRootPath 属性将使您能够访问应用程序内容文件的绝对路径.

                  The ContentRootPath property will give you access to the absolute path to the application content files.

                  您也可以使用属性 WebRootPath 如果你想访问 web-servable 根路径(默认为 www 文件夹)

                  You may also use the property, WebRootPath if you would like to access the web-servable root path (www folder by default)

                  您可以将此依赖项注入您的控制器并按如下方式访问它:

                  You may inject this dependency into your controller and access it as follows:

                  public class HomeController : Controller
                      {
                          private readonly IHostingEnvironment _hostingEnvironment;
                  
                          public HomeController(IHostingEnvironment hostingEnvironment)
                          {
                              _hostingEnvironment = hostingEnvironment;
                          }
                  
                          public ActionResult Index()
                          {
                              string webRootPath = _hostingEnvironment.WebRootPath;
                              string contentRootPath = _hostingEnvironment.ContentRootPath;
                  
                              return Content(webRootPath + "
                  " + contentRootPath);
                          }
                      }
                  

                  更新 - .NET CORE 3.0 及更高版本

                  @amir133 指出,IHostingEnvironment 已被 .NET Core 3.0 标记为过时.您应该使用 IWebHostEnvironment 而不是 IHostingEnvironment.请参考该答案下文.

                  IHostingEnvironment has been marked obsolete with .NET Core 3.0 as pointed out by @amir133. You should be using IWebHostEnvironment instead of IHostingEnvironment. Please refer to that answer below.

                  Microsoft 在这些接口之间巧妙地分离了主机环境属性.请参考下面的接口定义:

                  Microsoft has neatly segregated the host environment properties among these interfaces. Please refer to the interface definition below:

                  namespace Microsoft.Extensions.Hosting
                  {
                    public interface IHostEnvironment
                    {
                      string EnvironmentName { get; set; }
                      string ApplicationName { get; set; }
                      string ContentRootPath { get; set; }
                      IFileProvider ContentRootFileProvider { get; set; }
                    }
                  }
                  
                  namespace Microsoft.AspNetCore.Hosting
                  {
                    public interface IWebHostEnvironment : IHostEnvironment
                    {
                      string WebRootPath { get; set; }
                      IFileProvider WebRootFileProvider { get; set; }
                    }
                  }
                  

                  这篇关于ASP.NET Core 中的 Server.MapPath 等价物是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is the difference between Funclt;string,stringgt; and delegate?(Funclt;string,stringgt; 有什么区别?和委托?)
                  What is the difference between lt;%: and lt;%= in ASP.NET MVC?(ASP.NET MVC 中的 lt;%: 和 lt;%= 有什么区别?)
                  linq query for tag system - search for multiple tags(标签系统的 linq 查询 - 搜索多个标签)
                  Forum tags. What is the best way to implement them?(论坛标签.实施它们的最佳方法是什么?)
                  html script tag not using type javascript lt;script type=quot;text/htmlquot;gt;?(html 脚本标签未使用类型 javascript lt;script type=quot;text/htmlgt;gt;?)
                  ASP.NET Control to HTML tag equivalent(ASP.NET 控件到 HTML 标记等效)
                    <bdo id='XTzyy'></bdo><ul id='XTzyy'></ul>

                    <small id='XTzyy'></small><noframes id='XTzyy'>

                        • <legend id='XTzyy'><style id='XTzyy'><dir id='XTzyy'><q id='XTzyy'></q></dir></style></legend>
                          <tfoot id='XTzyy'></tfoot>
                            <i id='XTzyy'><tr id='XTzyy'><dt id='XTzyy'><q id='XTzyy'><span id='XTzyy'><b id='XTzyy'><form id='XTzyy'><ins id='XTzyy'></ins><ul id='XTzyy'></ul><sub id='XTzyy'></sub></form><legend id='XTzyy'></legend><bdo id='XTzyy'><pre id='XTzyy'><center id='XTzyy'></center></pre></bdo></b><th id='XTzyy'></th></span></q></dt></tr></i><div id='XTzyy'><tfoot id='XTzyy'></tfoot><dl id='XTzyy'><fieldset id='XTzyy'></fieldset></dl></div>

                              <tbody id='XTzyy'></tbody>