File Path for PersistKeysToFileSystem on shared serverHow do I get the path of the assembly the code is in?How to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?ASP.NET MVC Relative PathsHow can I get the application's path in a .NET console application?ASP.NET MVC relative path for a jQuery spinner imageFile Upload ASP.NET MVC 3.0Yet another aspnet file path questionWant to place data files for WinForm app in folder and get its path in codeCould not find a part of the path … binroslyncsc.exeGet XML comments output file location for ASP Core

Is it wrong to omit object pronouns in these sentences?

Formal Definition of Dot Product

OSPF increase bandwidth with load-balancing

Why did the metro bus stop at each railway crossing, despite no warning indicating a train was coming?

Who commanded or executed this action in Game of Thrones S8E5?

Polynomial division: Is this trick obvious?

Uh oh, the propeller fell off

Can a tourist shoot a gun for recreational purpose in the USA?

Can my Serbian girlfriend apply for a UK Standard Visitor visa and stay for the whole 6 months?

Do not cross the line!

Under what charges was this character executed in Game of Thrones, The Bells?

Find the unknown area, x

Adding labels and comments to a matrix

Use of さ as a filler

Why do the lights go out when someone enters the dining room on this ship?

Is it safe to use two single-pole breakers for a 240 V circuit?

Why can't I share a one use code with anyone else?

The meaning of the Middle English word “king”

the grammar about `adv adv` as 'too quickly'

How to make a not so good looking person more appealing?

Will a coyote attack my dog on a leash while I'm on a hiking trail?

Why weren't the bells paid heed to in S8E5?

How to not get blinded by an attack at dawn

Promotion comes with unexpected 24/7/365 on-call



File Path for PersistKeysToFileSystem on shared server


How do I get the path of the assembly the code is in?How to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?ASP.NET MVC Relative PathsHow can I get the application's path in a .NET console application?ASP.NET MVC relative path for a jQuery spinner imageFile Upload ASP.NET MVC 3.0Yet another aspnet file path questionWant to place data files for WinForm app in folder and get its path in codeCould not find a part of the path … binroslyncsc.exeGet XML comments output file location for ASP Core






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















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


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.



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?










share|improve this question




























    1















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


    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.



    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?










    share|improve this question
























      1












      1








      1








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


      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.



      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?










      share|improve this question














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


      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.



      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?







      c# asp.net-mvc asp.net-core-mvc asp.net-core-identity asp.net-core-mvc-2.0






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 23 at 14:40









      BojanBojan

      2,293112980




      2,293112980






















          1 Answer
          1






          active

          oldest

          votes


















          3














          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






          share|improve this answer























          • When you say app folder, you mean root directory of the website?

            – Bojan
            Mar 23 at 15:01











          • Yes exactly, alongside the wwwroot folder (but not inside that or the files may get served to the browser)

            – DavidG
            Mar 23 at 15:02











          • As for IHostingEnvironment, do I inject that with IServiceCollection then?

            – Bojan
            Mar 23 at 15:04











          • It's injected into Startup as I show here.

            – DavidG
            Mar 23 at 15:11











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55314845%2ffile-path-for-persistkeystofilesystem-on-shared-server%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          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






          share|improve this answer























          • When you say app folder, you mean root directory of the website?

            – Bojan
            Mar 23 at 15:01











          • Yes exactly, alongside the wwwroot folder (but not inside that or the files may get served to the browser)

            – DavidG
            Mar 23 at 15:02











          • As for IHostingEnvironment, do I inject that with IServiceCollection then?

            – Bojan
            Mar 23 at 15:04











          • It's injected into Startup as I show here.

            – DavidG
            Mar 23 at 15:11















          3














          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






          share|improve this answer























          • When you say app folder, you mean root directory of the website?

            – Bojan
            Mar 23 at 15:01











          • Yes exactly, alongside the wwwroot folder (but not inside that or the files may get served to the browser)

            – DavidG
            Mar 23 at 15:02











          • As for IHostingEnvironment, do I inject that with IServiceCollection then?

            – Bojan
            Mar 23 at 15:04











          • It's injected into Startup as I show here.

            – DavidG
            Mar 23 at 15:11













          3












          3








          3







          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






          share|improve this answer













          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







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 23 at 14:49









          DavidGDavidG

          74.2k9123137




          74.2k9123137












          • When you say app folder, you mean root directory of the website?

            – Bojan
            Mar 23 at 15:01











          • Yes exactly, alongside the wwwroot folder (but not inside that or the files may get served to the browser)

            – DavidG
            Mar 23 at 15:02











          • As for IHostingEnvironment, do I inject that with IServiceCollection then?

            – Bojan
            Mar 23 at 15:04











          • It's injected into Startup as I show here.

            – DavidG
            Mar 23 at 15:11

















          • When you say app folder, you mean root directory of the website?

            – Bojan
            Mar 23 at 15:01











          • Yes exactly, alongside the wwwroot folder (but not inside that or the files may get served to the browser)

            – DavidG
            Mar 23 at 15:02











          • As for IHostingEnvironment, do I inject that with IServiceCollection then?

            – Bojan
            Mar 23 at 15:04











          • It's injected into Startup as I show here.

            – DavidG
            Mar 23 at 15:11
















          When you say app folder, you mean root directory of the website?

          – Bojan
          Mar 23 at 15:01





          When you say app folder, you mean root directory of the website?

          – Bojan
          Mar 23 at 15:01













          Yes exactly, alongside the wwwroot folder (but not inside that or the files may get served to the browser)

          – DavidG
          Mar 23 at 15:02





          Yes exactly, alongside the wwwroot folder (but not inside that or the files may get served to the browser)

          – DavidG
          Mar 23 at 15:02













          As for IHostingEnvironment, do I inject that with IServiceCollection then?

          – Bojan
          Mar 23 at 15:04





          As for IHostingEnvironment, do I inject that with IServiceCollection then?

          – Bojan
          Mar 23 at 15:04













          It's injected into Startup as I show here.

          – DavidG
          Mar 23 at 15:11





          It's injected into Startup as I show here.

          – DavidG
          Mar 23 at 15:11



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55314845%2ffile-path-for-persistkeystofilesystem-on-shared-server%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현