The short answer is:
ViewStarts start first when any view is being rendered. The long story is below:
The story of the creation of a single view file:
- The ViewStart is merged with ViewImports and then executed as a single file. Note that ViewImports is always merged with any cshtml file including the ViewStart file. Its purpose is to abstract @using statements and other common directives.
- The output of ViewStart (such as Layout and ViewData) becomes available to the specific View file.
- Inside the View file, if the Layout variable is/becomes null, the body of the view is rendered and the final output is delivered to the user.
- If the Layout variable is/becomes not null, the execution is moved to the layout file which in turn is merged with ViewImports as a single file and then at the @RenderBody() statement inside the layout file execution is moved back to the view file which is merges with ViewImports again and the output is merged with the layout file at the location of @RenderBody() and the final output is finally delivered to the user.
Hopes this makes you aware of what's really going on inside the unknown mysteries of your program's life cycle.