简体   繁体   English

如何在ASP的网站项目中读取.resx文件的属性。 DLL程序集的网络

[英]How to read the properties of an .resx file in a Web site project of asp. Net from a dll assembly

I'm new in .Net and working with two projects in c# a class library project(dll) and a website asp project. 我是.Net的新手,正在c#中处理两个项目,一个是类库项目(dll),另一个是网站ASP项目。

I need to read some properties from a file .resx that is in the App_GlobalResources folder of the website. 我需要从网站的App_GlobalResources文件夹中的.resx文件中读取一些属性。

Is there a way to read these properties in the .resx website file from a dll assembly more specifically in the method onPreRender?? 有没有一种方法可以从dll程序集中更具体地在onPreRender方法中读取.resx网站文件中的这些属性?

Thanks for you attention 感谢您的关注

It sounds to me that you are having some problems with structuring and dependencies in your solution. 在我看来,您的解决方案在结构和依赖性方面存在一些问题。 (Trying to reference the website from a DLL) (尝试从DLL引用网站)

Generally speaking, your DLL should not need to access the resources of the website on its own - you should only pass them in through as parameters when calling various methods that are contained in the DLL itself. 一般来说,您的DLL不需要自己访问网站的资源-您仅应在调用DLL本身包含的各种方法时将它们作为参数传递。

Have you thought about migrating the resource file to the DLL? 您是否考虑过将资源文件迁移到DLL? That would allow both DLL and the website to read from it. 这将使DLL和网站都可以读取它。

Another option would be to migrate the setting you need to the .config file which you can read by using the ConfigurationManager class ( MSND Link ) 另一个选择是将所需的设置迁移到.config文件,您可以使用ConfigurationManager类( MSND Link )读取该文件。

You should be able to use it like this, even from your Code repository project: 即使在您的代码存储库项目中,您也应该可以这样使用它:

string settingValue = ConfigurationManager.AppSettings["YouSettingNameHere"].ToString();

However, if you really want to keep your current solution structure you can follow the answer that Pavel Chuchuva gave on a similar question here . 但是,如果您真的想保留当前的解决方案结构,则可以在此处按照Pavel Chuchuva对类似问题的回答。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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