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

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

      <tfoot id='pqakj'></tfoot>

        共享服务器上 PersistKeysToFileSystem 的文件路径

        时间:2023-07-10
      1. <tfoot id='6lCwy'></tfoot>
        1. <small id='6lCwy'></small><noframes id='6lCwy'>

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

                <tbody id='6lCwy'></tbody>

                  <bdo id='6lCwy'></bdo><ul id='6lCwy'></ul>
                  本文介绍了共享服务器上 PersistKeysToFileSystem 的文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试让我的密钥对登录的用户持续存在.由于我目前正在为网站使用共享主机,因此我决定使用文件系统来存储密钥环.所以代码看起来像这样:

                  I'm trying to make my keys persist for users that log in. As I'm currently using shared hosting for the website, I've decided to use the file system to store the keyring. So the code looks like this:

                  services.AddDataProtection()
                  .PersistKeysToFileSystem(new DirectoryInfo(""))
                  .SetApplicationName("MyWebsite")
                  .SetDefaultKeyLifetime(TimeSpan.FromDays(90))
                  .ProtectKeysWithCertificate(cert);
                  

                  但是,我不太了解我应该将这些钥匙放在哪里,以及我要经过什么路径才能让它们在那里.由于这是一个 MVC 核心应用程序,我有点困惑,在 MVC 5 中我会将它放在 App_Data 文件夹中,但这里没有 App_Data 文件夹,我想确保它保持安全并且无法通过浏览器访问.

                  However, what I'm not really understanding is where I should hold these keys, and what would be the path I pass in in order for them to be there. Since this is an MVC Core Application I am a little confused, in an MVC 5 I would put it in App_Data folder, but here there is no App_Data folder and I want to make sure it stays secure and cannot be accessed via the browser.

                  另一件事是我传递的是相对路径还是直接路径?如果是相对的,我的出发点在哪里?是bin、根目录还是别的什么?

                  The other thing is do I pass it a relative path or a direct path? If it is relative, where is my starting point? Is it bin, root directory or something else?

                  推荐答案

                  最简单的方法大概是在app文件夹里面创建一个文件夹.例如,创建一个名为 Keys 的文件夹,并使用 IHostingEnvironment 对象获取 app 文件夹.像这样的:

                  The simplest way is probably to create a folder inside the app folder. For example, create a folder called Keys, and use the IHostingEnvironment object to get the app folder. Something like this:

                  public class Startup
                  {
                      private readonly IHostingEnvironment _environment;
                  
                      public Startup(IHostingEnvironment environment)
                      {
                          _environment = environment;
                      }
                  
                      public void ConfigureServices(IServiceCollection services)
                      {
                          var keysFolder = Path.Combine(_environment.ContentRootPath, "Keys");
                  
                          services.AddDataProtection()
                              .PersistKeysToFileSystem(new DirectoryInfo(keysFolder))
                              .SetApplicationName("MyWebsite")
                              .SetDefaultKeyLifetime(TimeSpan.FromDays(90))
                              .ProtectKeysWithCertificate(cert);
                      }
                  
                      // snip
                  }
                  

                  这篇关于共享服务器上 PersistKeysToFileSystem 的文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:.Net Core Dependency Injection 从构造函数中注入 下一篇:Shaman.EPPlus + ASP.NET Core MVC - 部分已经存在异常

                  相关文章

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

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

                  1. <tfoot id='RV5DF'></tfoot>
                      <bdo id='RV5DF'></bdo><ul id='RV5DF'></ul>