获取Web应用程序的程序集的名称,而不考虑当前执行的程序集程序、而不、应用程序、名称

2023-09-03 00:48:18 作者:终相守

时可能会得到一个ASP.NET Web应用程序的程序集名称,从引用的程序集??

Is is possible to get the assembly name of an ASP.NET web application, from a referenced assembly??

Assembly.GetEntryAssembly在台式机和控制台应用程序工作得很好,但它似乎总是空的Web应用程序,并GetExecuting \ GetCallingAssebly回到我引用的程序集,而不是从Web应用程序之一。

Assembly.GetEntryAssembly worked fine in desktop and console apps but it seems to be always null in web apps, and GetExecuting\GetCallingAssebly return my referenced assembly, not the one from the web app.

龙解释:

我写的是不是从读取配置自定义设置提供商,应用程序配置文件,它从一个集中的配置服务获取的设置。

I wrote a custom Settings Provider, that instead of reading configuration from the app config file, it gets the settings from a centralized configuration service.

定制提供者是在一个单独的组件,以便它可以使用由不同的应用程序。

The custom provider is in a separate assembly so it can be used by the different applications.

的ApplicationName属性需要与应用程序集名称中指定。

The ApplicationName property needs to be overriden with the app assembly name.

要使用提供的方式是,虽然一个.net自定义属性,所以我不能发送任何PARAMS吧。

The way to use the provider is though a .net custom attribute, so I can't send any params to it.

由于非的Assembly.Get *装配方法似乎工作中,我能想到的是,需要与Web应用程序的应用程序名称的appSetting,但我不是很满意,唯一的事情。任何帮助,这是AP preciated,谢谢!

Since non of the Assembly.Get*Assembly methods seem to work, the only thing a I can think of is requiring an appSetting with the app name for web apps, but I'm not really happy with that. Any help with this is appreciated, thanks!

推荐答案

尝试

BuildManager.GetGlobalAsaxType().BaseType.Assembly