Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4246632
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:59:57+00:00 2026-05-21T03:59:57+00:00

currently I’m developing on an older ASP.NET MVC 1 Application, to add theme support.

  • 0

currently I’m developing on an older ASP.NET MVC 1 Application, to add theme support. I’ve looked around the web and was able to build my own ViewEngine which works quit nice so far. Only one problem is banging my had.

I’ve overwritten following method for WebFormViewEngine:

public override ViewEngineResult FindView(
    ControllerContext controllerContext, 
    string viewName, 
    string masterName, 
    bool useCache)

In this method I’m setting up the location formats for the theme support. Unfortunately the masterName Parameter is always empty! So I need to check

if (string.IsNullOrEmpty(masterName))    
    masterName = "Site";

always by myself to get the engine working. But as I’ve several master files, this solution sucks, as soon as a view requires another master than “Site”.
Does anybody know, how I can get the master views name in this Method?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T03:59:57+00:00Added an answer on May 21, 2026 at 3:59 am

    Solved it by myself. After a lot of researching, I’ve found following snippet, which helped me:

    private void RenderViewPage(ViewContext context, ViewPage page)
                {
                    if (!String.IsNullOrEmpty(MasterPath)) {
                        page.MasterLocation = MasterPath;
                    } else {
                        if (sc.WIP.CarharttIMD.Common.Config.GetStringValue("Theme") != "Default")
                            page.PreInit += new EventHandler(page_PreInit);
                    }
    
                    page.ViewData = context.ViewData;
                    page.RenderView(context);
                }
    
    void page_PreInit(object sender, EventArgs e)
                {
                    ViewPage page = sender as ViewPage;
                    //test for Default theme path, and replace with current theme
                    string defaultthemepath = string.Format("{0}Content/Default", page.Request.ApplicationPath);
                    if (!string.IsNullOrEmpty(page.MasterPageFile) && !page.MasterPageFile.ToLower().StartsWith(defaultthemepath.ToLower()))
                    {
                        string masterPagePath = page.MasterPageFile;
                        int lastIndexOfSlash = masterPagePath.LastIndexOf('/');
                        string masterPageName = masterPagePath.Substring(lastIndexOfSlash + 1, masterPagePath.Length - lastIndexOfSlash - 1);
                        string newMaster = string.Format(
                            "~/Content/{0}/Views/Shared/{1}",
                            Common.Config.GetStringValue("Theme"),
                            masterPageName
                        );
                        if (File.Exists(page.Server.MapPath(newMaster)))
                            page.MasterLocation = newMaster;
                    }
                }
    

    Had to subclass the WebViewForm and handeling the master File in the PreInit event.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I am using Amazon Cloudfront to service static objects on my ASP.Net MVC3
Currently, I am writing a MiddleWare application that synchronizes information between and accounting application
Currently i have a node.js and socket.io application in development on my local machine
currently I'm developing an app for WP7 but came across a little problem with
Currently, my MVC 3 app has a dependency on a static class that is
Currently I have the following Mapping in my Controller: @RequestMapping( value = /add.html, method
Currently I have a web service running in a tomcat (http:// localhost:8080/myApp/getUsers ). My
Currently I have a web service, which loads up any plugins located within its
Currently, I have a GWT based application /app.htm It displays an openId login button
Currently i am consuming web service from android by the method SOAP.Here i need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.