Geeks With Blogs
Going, going, gone awry Technical ramblings from John Summers
Getting near release time of a n-tiered system with multiple applications accessing the BLL/DAL framework? You want to make sure that what you think you're accessing really is the version you think it is. Using the AppDomain, you can get and parse through the assemblies and find a particular attribute match. In the case below, I'm looking for the companyname. I put this into a user control and applications can use it in a "help" or "about" page. This has come in handy for me, when you realize you've not updated your referenced or the GAC assembly. The key for asp.net apps is to add the App_Code folder and put an AssemblyInfo.cs file with the proper assembly information in it. (You DO need to remember to update that).

the aspx code-
   <asp:Repeater ID="Assemblyrptr" runat="server">
        <headertemplate>
        Assemblies:<br />
        </headertemplate>
        <itemtemplate>
        <%#Container.DataItem%>
        <br />
        </itemtemplate>

    </asp:Repeater>

the code behind C#-
    protected void Page_Load(object sender, EventArgs e)
    {
        AppDomain currentDomain = AppDomain.CurrentDomain;
        //Load the assembly from the application directory using a simple name.
        //Make an array for the list of assemblies.
        Assembly[] assems = currentDomain.GetAssemblies();
        List<Assembly> appassemlist = assems.ToList<Assembly>();
        List<string> assemList = new List<string>();
        foreach (Assembly appassem in appassemlist)
        {
            AssemblyCompanyAttribute mdtName = (AssemblyCompanyAttribute)Attribute.GetCustomAttribute(appassem, (typeof(AssemblyCompanyAttribute)));
            if (mdtName != null && mdtName.Company.StartsWith("yourcompanynamehere"))
                assemList.Add(appassem.FullName);
        }
        Assemblyrptr.DataSource = assemList;
        Assemblyrptr.DataBind();

    }


On a different subject but, same idea, you can grab the asp.net app_code assembly, stuff it in cache and use it in the master page footer.

    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        log4net.Config.XmlConfigurator.Configure();
        AppDomain currentDomain = AppDomain.CurrentDomain;
        //Load the assembly from the application directory using a simple name.
        //Make an array for the list of assemblies.
        Assembly[] assems = currentDomain.GetAssemblies();
        Assembly myassm = this.GetType().Assembly;
        int i = 0;
        for (i = 0; i < assems.Length; i++ )
        {
            if (assems[i].FullName.StartsWith("Deploy") || assems[i].FullName.StartsWith("App_Code") )
            {
                myassm = assems[i];
                Application.Add("Assembly", myassm);
                break;
            }
        }
       //This is another way to do it - this works too.
        //Application.Add("Assembly", System.Reflection.Assembly.Load("App_Code/AssemblyInfo.cs"));

    } Posted on Friday, November 7, 2008 8:07 PM ASP.NET | Back to top


Comments on this post: Finding assembly information of an asp.net website

Comments are closed.
Comments have been closed on this topic.
Copyright © goinawry | Powered by: GeeksWithBlogs.net