News

Subscribe!

Disclaimer

This blog and the postings therein are provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the general copyright terms.

My Stats

  • Posts - 100
  • Comments - 35
  • Trackbacks - 38

Twitter












Tag Cloud


Recent Comments


Recent Posts


Article Categories


Archives


Post Categories


Image Galleries


.NET Links


.Text Links


Blogs i read...


eGovernment


ePolicing


Microsofty


Misc.


Mountain Biking


MS Patterns & Practices


November 2005 Entries

TRUE TALES OF INDUHVIDUALS


From Dilbert Newsletter
Normally I would include in this section all of the tales of Induhviduals reported by vigilant DNRC operatives in the field. Today I have only one, because after this one, nothing else will seem Induhvidually enough: -- One of my co-workers (who is originally from Arkansas, just FYI) told me one day that he knew for a fact that sex feels better for women than it does for men. I asked, "How do you figure that?" His reply was (and I am not making this up!), "Because when you put your finger in your ear and wiggle it around, it feels better to your ear than it does to your finger."

posted @ Friday, November 18, 2005 6:39 AM | Feedback (1) |


RE: Sharing Master Pages Across IIS Applications


I'm working on an ASP.NET site that consists of many government departments each having their own IIS application off of the root of the server so that they can have complete control over their own web.config file, etc..  Each department site inherited an XML template framework I wrote for .NET version 1.1 (http://www.xmlforasp.net/codeSection.aspx?csID=102) to provide a consistent look and feel (header and footer) across all departments even though they each have their own IIS application created.  The XML template solution worked great but wasn't as powerful as Master Pages by any means since it didn't support code-behind files and had no designer support (to name just 2 of its short-comings).

In migrating some of the department sites to .NET V2 and Master Pages I ran into the problem of sharing the master page located at the root of the site across all of the child department sites.  Since master pages are derived from user controls they can't be shared across IIS applications (without some virtual directory hacks anyway).  After being pointed to an excellent article Microsoft's Scott Guthrie wrote (http://weblogs.asp.net/scottgu/archive/2005/08/28/423888.aspx) about re-using User Controls and other things across ASP.NET sites (thanks Matias) and playing around with the concept awhile, I believe I have a way to share master pages across multiple IIS applications.  In a nutshell, I stick the root master page in the GAC.

Here are the steps I went through.  I haven't done extension testing (only a basic master page without links to images or anything) but the simple solution seems to work great.

1.  Create an empty Website in VS.NET 2005 (delete anything in it including App_Data and Default.aspx).
2.  Add a master page into the Website.  I created a very simple master page named MasterPageBase.master:

<%@ Master Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml

3.  Select Build | Publish Website from the VS.NET menu.
4.  On the screen that follows select a target site, and check all of the checkboxes except for the top one that allows for dynamic updates.  Note that I reference a strong name key file named keyfile.snk that I created using the sn.exe command-line tool that ships with .NET.  This is required in order to install assemblies into the GAC.  I used the following syntax to create the file:  sn.exe -k keyfile.snk

 

5.  After the publish operation completes, open the new Website in VS.NET 2005 (named MasterDemo in the example above).  You should see a new assembly (with a somewhat strange name) in the Bin folder.  This assembly is your master page in compiled form.
6.  Install the assembly into the GAC using gacutil.exe or drag-and-drop it into c:\Windows\Assembly using Windows Explorer.  Once you've done this delete the original assembly as well as the newly created XML files associated with it from the Website.
7.  Add a web.config file into your project and add the following within the <system.web> begin and end tags.  You'll need to change the name of the assembly to the name that is generated for your project (the one you added into the GAC) and change the PublicKeyToken to the one you see in the GAC.  Note that the assembly attribute value shouldn't wrap at all.  I didn't give my base master page a version for simplicity here but you can by applying the [assembly: AssemblyVersion("1.0.0.0")] attribute to the master page code-behind class.

<compilation debug="true">
   <assemblies>
     <add assembly="App_Web_masterpagebase.master.cdcab7d2, Version=0.0.0.0,
        Culture=neutral, PublicKeyToken=cceb8435cfc68486" />
   </assemblies>
</compilation>

8.  Add a master page into the Website but don't create a code-behind page for it (you can...but it's not needed in this case).  I named mine MasterPage.master.
9.  Remove all code within the new master page and add the following at the top (it should be the ONLY code in the page).  If you named your original master page (the one created in step 2) differently then you'll need to change your Inherits value.  Use the object browser to see the name of your class that is within the .dll generated in step 4.  It should be within an ASP namespace.

<%@ Master Language="C#" Inherits="ASP.masterpagebase_master" %>

10.  Create a content page that references MasterPage.master (the one you created in the previous step).  The default ContentPlaceHolderID is ContentPlaceHolder1 so use that in the <asp:Content> tag unless you gave the id a different name in step 2. 

These 10 steps probably seem like a lot of work, but now any sub IIS application can leverage the same master page used by other IIS applications by placing the empty MasterPage.master file into the application and updating the web.config file to point to the master page assembly in the GAC.  The downfall of this is that you of course have to recompile the base master page and put it back into the GAC each time you need to make a change....I haven't tried the dynamic updating option at all.

I haven't had time to experiment with ways to break this (although there's probably a better way to do this or something that will break that I haven't encountered yet) but to this point it seems to work for the situation I needed it for and offers a way to potentially share user controls across IIS applications as well....like you've always been able to do with server controls placed in the GAC.

 

 

" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        Header
        <br />
        <asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
        </asp:contentplaceholder>
        <br />
        Footer
    </div>
    </form>
</body>
</html>
[Via Weblogs @ ASP.NET]
[Listening to: Star Guitar - The Chemical Brothers - Come with Us (06:27)]

posted @ Thursday, November 17, 2005 11:02 AM | Feedback (4) |