简体   繁体   English

运行ASP.NET WebForms应用程序时从类库的代码中读取安全的.pem文件

[英]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.

相关问题 ASP.NET中的类库中的Webforms - Webforms in class library in asp.net 是否可以在另一个解决方案中从 ASP.NET Webforms 项目中引用 ASP.NET Core 2.0 类库 dll? - Possible to reference an ASP.NET Core 2.0 class library dll from an ASP.NET Webforms project in another solution? 使用LINQ从ASP.net中的Webforms调用类库项目中编写的方法到实体 - Calling methods written in class library project from webforms in ASP.net using LINQ to entities 将应用程序从 Asp.Net Webforms 更新到 .Net 6 - Update Application From Asp.Net Webforms to .Net 6 创建 web 服务以从 C# ASP.NET webforms 应用程序访问 class object 公共方法 - Create web service to access class object public methods from C# ASP.NET webforms application 使用表单身份验证在ASP.NET Webforms App外部的类库中检索当前登录的用户ID - Retrieving the current logged in user's Id in a class library outside of an ASP.NET Webforms App using forms authentication 在ASP.NET Web表单上运行异步任务 - Running Async tasks on asp.net webforms 将CKEditor集成到ASP.Net Webforms应用程序中 - Integrating CKEditor in an ASP.Net Webforms Application 调试时,ASP.NET Webforms项目正在从PC上完全不同的解决方案中的web.config中读取 - ASP.NET Webforms project is reading from a web.config in a completely different solution on my PC when debugging ASP.NET Webforms中ListView中的内联代码? - Inline Code in ListView in ASP.NET Webforms?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM