roy roy

roy roy

  • NA
  • 27
  • 0

Using a master page in multiple web sites

Dec 30 2007 9:06 PM

Hello.
Your help is very much appreciated.

I want to share a master page between a number of web sites. I’m doing it through:
1. Create the master page and put it in its own,separate, physical folder.
2. Create in the web site a virtual folder that points to the physical location of the master page.
3. Load the master page in the PageInit  method.

The code :
public partial class Default9 : System.Web.UI.Page
{

    public Default9()
   {
       this.PreInit += new EventHandler(Default9_PreInit);
   }

    protected void Default9_PreInit(object sender, EventArgs e)
    {
        this.MasterPageFile ="http://localhost/test/vf/Site1.Master
    }
}

(the virtual folder is called vf and it points to the physical location where the master page is located. The web site itself is named ‘test’)

The problem: I’m getting error “'http://localhost/test/vf/Site1.Master' is not a valid virtual path.”

I tried to change it to this.MasterPageFile = "vf/Site1.Master"
But that throws an error “The file '/test/vf/Site1.Master' does not exist. “;

Thank you,
Roy

(references http://www.odetocode.com/Articles/450.aspx)


Answers (2)