Get module name at runtime

Apr 9, 2009 at 7:14 AM
Edited Apr 10, 2009 at 3:46 AM
Hi,
How would I get the name of the current business module at runtime?
eg. I have a class defined in Shell module. It is used in ModuleA and ModuleB. The class needs to know if it is running in A or B.

k
Apr 10, 2009 at 3:39 AM
Edited Apr 10, 2009 at 3:46 AM

first attempt..

string currentPath = Context.Request.AppRelativeCurrentExecutionFilePath;

string currentModuleName;
ModulesConfigurationSection moduleConfig = ConfigurationManager.GetSection("compositeWeb/modules") as ModulesConfigurationSection;

foreach (ModuleConfigurationElement each in moduleConfig.Modules)
{
    if (each.Name != "Shell")
    {
        bool found = currentPath.Contains(each.VirtualPath);
        if (found)
        {
            currentModuleName = each.Name;
        }
    }
}  

That works but feels dirty. Is there a 'proper' way?