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

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript