我有一个ASP.NET应用程序和类库项目的解决方案。 ASP.NET应用程序正在使用类库项目。
我想检查类库中ASP.NET应用程序的程序集名称。
实际上我有一个带有单独Model项目的MVC应用程序。 MVC应用程序使用Model项目。我在另一个项目中创建了一个RemoteWithServerSideAttribute
并在模型中使用它。在RemoteWithServerSideAttribute
类中,我需要控制器程序集信息来调用方法。如果我使用Assembly.GetCallingAssembly
,我会收到System.ComponentModel.DataAnnotations
汇编信息,因为RemoteWithServerSideAttribute
是从RemoteAttribute
内的System.ComponentModel.DataAnnotations
继承的。
我想要的是获取MVC项目的程序集信息。
答案 0 :(得分:1)
不确定这是否是您要找的,但您可以使用System.Reflection来获取执行装配信息或条目装配信息。
因此,如果您从Web应用程序调用ClassLibrary中的方法,那么;
System.Reflection.Asembly.GetExecutingAssembly().GetName().Name
会为您提供类库的名称
System.Reflection.Assembly.GetCallingAssembly().GetName().Name
将为您提供Web应用程序的名称。
答案 1 :(得分:1)