2

im extremely curious about exceptional situation between asp.net mvc (4.7.2) and asp.net core mvc (2.2).

What im doing is:

Create empty asp.net mvc project , add new "TestController" cloned from default "HomeController" , duplicate views of home controller and name View directory as "Test".

doing exactly the same on asp.net core mvc project.

run asp.net mvc project and change url as /Test/Index (the view is exactly the same as Home/Index) and it took ~300ms to run on first time. if i refresh the page it took ~5-6 milliseconds to run.

im doing exactly the same on asp.net core mvc project and it took ~30 ms on first run and ~5-6 ms on every time i refresh.

i tested several cases and i think its all about "First creation of X type of controller".

im working on asp.net on 5-6 years but i've noticed this now. you can say it's no problem just 300 ms , but on the low resourced machine it took ~30 seconds.

what is this all about and how can i reduce this time to asp.net core time (~30ms) ?

EDIT: it turns out its not about the creation of controller. It's about the directories of views. I changed the Index action of TestController's view path with "~/Views/Home/Index" it opened fast (if i rendered any view from this folder before) , but if i "first time render a view from X directory (or sub directory) it works slowly as i mentioned."

i think its all about compiling views (or view directories). but im not figure it out yet.

consequently , if i move all my view files to same directory , this case never happens. but it will be very confusing and not feel right approach.

1 Answer 1

0

I finally figured it out. It's all about compiling views at starting the application (not at runtime).

And its speeding up your website (especially if you have too many views)

Solution:

  1. Unload project
  2. Right click on the unloaded project and go > "Edit *.csproj"
  3. Paste these settings to bottom line of the file

    <Target Name="BeforeBuild"> <!-- Remove obj folder --> <RemoveDir Directories="$(BaseIntermediateOutputPath)" /> <!-- Remove bin folder --> <RemoveDir Directories="$(BaseOutputPath)" /> </Target>

  4. Reload the project

  5. Paste this code to global asax > Application_Start

    var siteId = "1"; // you can find your own from applicationhost.config
    var appVirtualDir = $"/LM/W3SVC/{siteId}/ROOT";
    var clientBuildManager = new ClientBuildManager(appVirtualDir, null, null,
                                new ClientBuildManagerParameter
                                {
                                    PrecompilationFlags = PrecompilationFlags.Default,
                                });
    clientBuildManager.PrecompileApplication();
    
  6. Run the project

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.