简体   繁体   中英

Reading a secure .pem file from a class library's code when running ASP.NET WebForms application

I have an ASP.NET Solution with a Webforms app and a class library. In the class library there is text that needs to read from a .pem file using

File.ReadAllText('PATH GOES HERE')

Currently the .pem file is sitting in the root directory of the class library. Is there any possible way to tell the code to access it from here? It seems like it keeps looking for it at:

C:\\Program Files (x86)\\IIS Express\\private_key.pem

Should I store this file somewhere else?

I need a secure place to store it where only the File.ReadAllText can access it and not anyone through the website.

In WinForm App, use

string fileName = "~/relative/path/to/privacy_key.pem";
string absolutePath = Server.MapPath(fileName);

Then in your Class Library, you can easily read the file using the absolute path.

You can also store the .pem path in Web.config , so that it's easy to configure in the future.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM