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 6575737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:25:28+00:00 2026-05-25T15:25:28+00:00

I have an older ASP.NET MVC application that uses classic web forms views. As

  • 0

I have an older ASP.NET MVC application that uses classic web forms views. As an experiment, we’ve started to mix in some razor views. Unfortunately, the default precedence for where to find the desired view isn’t what I want. MVC first looks in your /Views/ControllerName folder for aspx and ascx files. Then it moves to your /Views/Shared for aspx and ascx files. Then it starts over looking for .cshtml and .vbhtml files. What I want is for it not to go into the Shared folder until it’s exhausted all the possibilities in the /Views/ControllerName folder. How do I do this?

— UPDATE —

Here’s some additional information that might help explain what I’m after. By default, I get this search order:

~/Views/Home/Index.aspx
~/Views/Home/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/Home/Index.cshtml
~/Views/Home/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml 

What I want is this:

~/Views/Home/Index.aspx
~/Views/Home/Index.ascx
~/Views/Home/Index.cshtml
~/Views/Home/Index.vbhtml
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml

In other words, it shouldn’t search Shared before it searches the /Views/ControllerName folder completely.

  • 1 1 Answer
  • 0 Views
  • 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-25T15:25:29+00:00Added an answer on May 25, 2026 at 3:25 pm

    After toying with it a bit, I was able to achieve what I wanted with a simple Fluent API. The extension methods remove the search locations I didn’t want from each of the view engines. The search locations are stored in .ViewLocationFormats and .PartialViewLocationFormats string arrays. So here’s the fluent API that removes the unwanted items from those arrays:

    public static class BuildManagerViewEngineFluentExtensions {
        public static BuildManagerViewEngine ControllerViews(this BuildManagerViewEngine engine) {
            return FilterViewLocations(engine, x => x.Contains("/Views/Shared/") == false);
        }
    
        public static BuildManagerViewEngine SharedViews(this BuildManagerViewEngine engine) {
            return FilterViewLocations(engine, x => x.Contains("/Views/Shared/") == true);
        }
    
        private static BuildManagerViewEngine FilterViewLocations(BuildManagerViewEngine engine, Func<string, bool> whereClause) {
            engine.ViewLocationFormats = engine.ViewLocationFormats.Where(whereClause).ToArray();
            engine.PartialViewLocationFormats = engine.PartialViewLocationFormats.Where(whereClause).ToArray();
            return engine;
        }
    }
    

    And then, in my global.asax, I added the following lines to protected void Application_Start()

    ViewEngines.Engines.Clear();
    ViewEngines.Engines.Add(new RazorViewEngine().ControllerViews());
    ViewEngines.Engines.Add(new WebFormViewEngine().ControllerViews());
    ViewEngines.Engines.Add(new RazorViewEngine().SharedViews());
    ViewEngines.Engines.Add(new WebFormViewEngine().SharedViews()); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ASP.NET MVC 3 application, using Entity Framework 4 to handle Data
I have a site built in ASP.NET MVC and uses heavy jQuery client interaction
I have an asp.net application that i am modifying. I setup visual studio 2010
Here is my scenario. I have an ASP.NET MVC solution with 3 projects. Data,
I have a new web app that is packaged as a WAR as part
I have 6 question in 6 asp.net panel server control , I need to
I have a project that adds elements to an AutoCad drawing. I noticed that
I have a script that appends some rows to a table. One of the
I have several USB mass storage flash drives connected to a Ubuntu Linux computer
I have a snippet to create a 'Like' button for our news site: <iframe

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.