[英]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. 我有一个带有Webforms应用程序和类库的ASP.NET解决方案。 In the class library there is text that needs to read from a .pem file using
在类库中,需要使用.pem文件读取文本
File.ReadAllText('PATH GOES HERE')
Currently the .pem file is sitting in the root directory of the class library. 目前,.pem文件位于类库的根目录中。 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
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. 我需要一个安全的位置来存储它,只有File.ReadAllText可以访问它,而任何人都不能通过网站访问它。
In WinForm App, use 在WinForm App中,使用
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. 您还可以将.pem路径存储在
Web.config
,以便将来轻松配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.