Purpose : To apply custom master page on the application pages apart from the custom pages.
Normally in a sharepoint site ,we find that look and feel of the site is not consistent through out the site, there may be application pages which are different from the home page of the site.Now the problem is that since these are admin pages , so we cannot do much modification on these pages, and moreover if we go in sharepoint designer and changes the page from there than these changes will appear at farm level. So there is another way branding these admin pages is through HTTP Module, which will change the master page of a particular admin page at run time without effecting any thing on the page. This way we can have consistent look and feel through out the site.
Steps :
1) Open visual studio
2) Create a new project of type class library
3) Add sharepoint reference to it
4) Inherit the class from “IHttpModule” class
Follow this code:
namespace MyModule
{
public class LogoutModule : IHttpModule //inherit from the class
{
public void Init(HttpApplication app)
{
// Create a event handler to execute the process
app.PreRequestHandlerExecute += new EventHandler(app_PreRequestHandlerExecute);
}
void app_PreRequestHandlerExecute(object sender, EventArgs e)
{
HttpContext context = HttpContext.Current; // Get the current context of the pagee
Page page = context.CurrentHandler as Page;
if(page!=null)
{
page.PreInit +=new EventHandler(page_PreInit);
}
}
// Application master page can be changed only on the PreInit method of the page only
void page_PreInit(object sender, EventArgs e)
{
Page page = sender as Page;
if (page != null)
{
if (page.MasterPageFile.Contains("application.master"))
{
page.MasterPageFile = @"\_LAYOUTS\CustomApplicationMaster\Customapplication.master";
}
}
}
public void Dispose()
{
}
}
}
Your job is done..
Enjoy!!!
No comments:
Post a Comment