Loading MasterPage form database

P

paul1664

Hi,

I'm currently loading my masterpage from a file via an httpmodule.

How can I modify this code to load the masterpage from a database? Is
the only way to save the file to a temp file first and load via
page.MasterPageFile?

Thanks,

Paul.



using System;
using System.Web;
using System.Web.UI;

public class MasterPageModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += new
EventHandler(context_PreRequestHandlerExecute);
}

void context_PreRequestHandlerExecute(object sender, EventArgs e)
{
Page page = HttpContext.Current.CurrentHandler as Page;
if (page != null)
{
page.PreInit += new EventHandler(page_PreInit);
}
}

void page_PreInit(object sender, EventArgs e)
{
Page page = sender as Page;
if (page != null)
{
page.MasterPageFile = "~/MasterPage.master";
}
}

public void Dispose()
{
}
}
 
B

bruce barker

yes, you have to write to a temp file, so the the aspnet_compiler can
see it.

-- bruce (sqlwork.com)
 
M

Mark Rae

How can I modify this code to load the masterpage from a database? Is
the only way to save the file to a temp file first and load via
page.MasterPageFile?

In addition to what Bruce said, a MasterPage by definition is going to get
called probably more than all the other pages in your app combined, so what
you're proposing to do is likely to be extremely inefficient in terms of
performance and resources.

Is there a specific reason you need to do this? MasterPages are very
flexible and quite easily programmable...
 
P

paul1664

It's just a requirement that my app will have a large number of
MasterPages (hundreds of clients, each with their own visual identity).


I understand what was said about performance but it would have been
nice to be given the option of, say, reading from db, storing to cache
and then subsequently loading from cache.

However, temp files are pretty straightforward though so shouldn't be a
problem.

Thanks for all you help,

Paul.
 
M

Mark Rae

It's just a requirement that my app will have a large number of
MasterPages (hundreds of clients, each with their own visual identity).

I have exactly the same requirement. Each client has their own MasterPage,
which I set when the site loads.

Go here: http://www.inthecage.co.uk and click the "Log in" button in the top
right-hand corner.

Now go here: http://www.sanctuaryrig.co.uk, enter the site, and click the
"Log in" button in the top right-hand corner.

Of course, it's exactly the same secure site, just with a different
MasterPage. No need for reading from a database, creating a temporary file
etc...
I understand what was said about performance but it would have been
nice to be given the option of, say, reading from db, storing to cache
and then subsequently loading from cache.

Again, there simply is no need whatsoever to do this...
However, temp files are pretty straightforward though so shouldn't be a
problem.

I see.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top