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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:32:00+00:00 2026-05-13T22:32:00+00:00

I created a simple ASP.NET MVC version 1.0 application. I have a ProductController which

  • 0

I created a simple ASP.NET MVC version 1.0 application. I have a ProductController which has one action Index. In the view, I created a corresponding Index.aspx under Product subfolder.

Then I referenced the Spark dll and created Index.spark under the same Product view folder. The Application_Start looks like

    protected void Application_Start()
    {
        RegisterRoutes(RouteTable.Routes);

        ViewEngines.Engines.Clear();
        ViewEngines.Engines.Add(new Spark.Web.Mvc.SparkViewFactory());

        ViewEngines.Engines.Add(new WebFormViewEngine());

    }

My expectation is that since the Spark engine registers before default WebFormViewEngine, when browse the Index action in Product controller, the Spark engine should be used, and WebFormViewEngine should be used for all other urls.

However, the test shows that the Index action for Product controller also uses the WebFormViewEngine.

If I comment out the registration of WebFormViewEnginer (the last line in the code), I can see that the Index action is rendered by Spark engine and the rest urls generates an error (since the defualt engine is gone), it proves that all my Spark code is correct.

Now my question is how the view engine is resolved? Why the registration sequence does not take effect?

  • 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-13T22:32:00+00:00Added an answer on May 13, 2026 at 10:32 pm

    The order in which you register the view engines doesn’t matter (much). Rather, view engines take a set of ViewLocationFormats, and if a particular view path fits the formatted name, that engine will be used. Only if you have conflicting formats does the registration order matter.

    In the case of spark, views should have the .spark extension. WebFormViewEngine will respond to any with .aspx or .ascx extensions. And of course, as mentioned above, you can override any of this by changing the ViewLocationFormats supplied to the individual view engines.


    Updated:

    I took a look through the source of both SparkViewFactory and WebFormViewEngine (or more specifically, VirtualPathProviderViewEngine, which the latter derives from), and I can tell you why you’re seeing this strange behaviour.

    First of all, the Find method in the ViewEngineCollection class works like this (simplified):

    foreach (IViewEngine engine in Items) {
        // Query engine for cached view
    }
    
    foreach (IViewEngine engine in Items) {
        // Query engine for uncached view
    }
    

    In other words, it will always try to find a cached view, in any engine, before resorting to uncached mode.

    The way in which individual view engines implement this is the second overload of the FindView method, which takes a bool argument named useCache.

    However, and here’s where it all gets weird – the VirtualPathProviderViewEngine and SparkViewEngine have very different ideas of what the useCache argument means. There’s too much code to repost here but the basic idea is:

    • The SparkViewFactory will look only in the cache if useCache is true. If it doesn’t find anything, it automatically returns a “cache miss result” – i.e. nothing. On the other hand, if useCache is false, it will not look in the cache at all, it will skip the cache-checking step and go through the normal motions to resolve and create an actual view.

    • The VirtualPathProviderViewEngine, on the other hand, looks in the cache if useCache is true, and if it doesn’t find the view in the cache, it goes off and creates a new one and adds that to the cache.

    Both of these approaches work with respect to the way ViewEngineCollection performs its search.

    • In the case of spark, it “misses” on the first iteration of view engines, but “hits” on the second, and after that the view is added to the cache. No problem.

    • In the case of VirtualPathProviderViewEngine, it “misses” internally but returns a “hit” anyway on the first iteration, at which point the view is now cached.

    So you should be able to see where the problem is here. The VirtualPathProviderViewEngine only appears to be taking precedence over the SparkViewEngine because the former always succeeds on the first (cached) iteration, but Spark only succeeds on the second (uncached) iteration.

    In plain English, Spark really does get asked first, but replies: “No, I don’t have that view yet. Try it without the cache instead.” WebForms gets asked second, but automatically says “I didn’t have that view, but I went and made one for you anyway, here it is.”. And from that point on, the WebFormViewEngine always gets priority because it has the view cached and Spark doesn’t.


    Summary: Spark is getting priority, but due to a quirk in the way Spark treats the useCache argument, it’s getting left in the dust when the Web Form engine is active at the same time. Either WebForm is over-eager or Spark is lazy, depending on your perspective.

    Simply put, the solution is not to have conflicting views! If you’ve registered multiple view engines, then you should be treating any view name which can be handled by either/both of them as undefined behaviour.

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

Sidebar

Ask A Question

Stats

  • Questions 378k
  • Answers 378k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer What I do. Create users manually. Do a dumpdata for… May 14, 2026 at 9:19 pm
  • Editorial Team
    Editorial Team added an answer It is possible in Drools DRL, but not in Guvnor.… May 14, 2026 at 9:19 pm
  • Editorial Team
    Editorial Team added an answer Solution 1 : open session in view filter Advantages :… May 14, 2026 at 9:19 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.