• <bdo id='tIQYW'></bdo><ul id='tIQYW'></ul>

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

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

    <legend id='tIQYW'><style id='tIQYW'><dir id='tIQYW'><q id='tIQYW'></q></dir></style></legend>
      1. 在 MVC 6 中读取文件

        Reading a file in MVC 6(在 MVC 6 中读取文件)
          <tbody id='Gem8G'></tbody>

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

              • <small id='Gem8G'></small><noframes id='Gem8G'>

                • 本文介绍了在 MVC 6 中读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想访问服务器主文件夹中的 create.sql 文件.它包含设置我的数据库的查询.我根本无法访问此文件.

                  I want to access my create.sql file in the main folder of my server. It contains queries to set up my database. I have a problem to access this file at all.

                  1) 我无法通过 Configuration 真正到达那里.我只能使用 AddJsonFileAddXmlFileAddIniFile.而且我想这不是将大 sql 文件放入其中的最佳主意.

                  1) I cannot really get there through Configuration. I can only use AddJsonFile, AddXmlFile, and AddIniFile. And I guess this is not the best idea to put a big sql file into any of those.

                  2) github 上的 Mvc 源 似乎缺少 MapPath.所以不可能使用 Server.MapPath("~/create.sql").

                  2) Mvc source on github seems to be missing MapPath. So no possibility of using Server.MapPath("~/create.sql").

                  那么如何实现呢?

                  推荐答案

                  正如评论中已经注意到和提到的,ASP.NET VNext (MVC 6) 中似乎没有 MapPath.我在这里找到了解决方法:

                  As already noticed and mentioned in the comments it seems that there is no MapPath in ASP.NET VNext (MVC 6). I found the workaround here:

                  http://forums.asp.net/t/2005166.aspx?HostingEnvironment+Equivalent+For+MapPath

                  基本上你需要从IApplicationEnvironment接口中获取ApplicationBasePath,该接口目前是作为服务实现的,如下解决方案:

                  Basically you need to get the ApplicationBasePath from IApplicationEnvironment interface, which currently is implemented as a service, following below the solution:

                      private readonly IApplicationEnvironment _appEnvironment;
                  
                      public HomeController(IApplicationEnvironment appEnvironment)
                      {
                          _appEnvironment = appEnvironment;
                      }
                  
                      public IActionResult Index()
                      {
                          var rootPath = _appEnvironment.ApplicationBasePath;
                          return View();
                      }
                  

                  这篇关于在 MVC 6 中读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                  Accessing attribute info from DTE(从 DTE 访问属性信息)
                  c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                  Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                  C# Attributes and their uses(C# 属性及其用途)
                  C# - Getting all enums value by attribute(C# - 按属性获取所有枚举值)
                • <small id='EeS92'></small><noframes id='EeS92'>

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