Most of you already know about it and rest are still confused and don't know what the hell is happening. This may help for the one who are still digesting the big changes and not sure what is going on! Story started long back (more than an year ago) and now have finally (I think) reached a much mature stage (comparatively). Big Name Change Starting with ASP.NET vNext (or vNext in general) with "K" set of tools. Then they renamed it to be called as ASP.NET 5 and finally settled with .NET Core 1.0 / ASP.NET Core 1.0. Scott wrote about it few months back and I recommend to take a read (really a short one - "Naming is hard."). Parallel Universe The .NET and Webstack continues the journey forward now in parallel. First: This one is "Windows Only" stack which currently includes .NET 4.6 » Read more

 Jsinh        

While I was working on some code today and found that some NuGet packages where out of date. So I went to update tab in Manage NuGet packages window and updated all of them. MySql.Data package (not important which package, just an example) was also updated in that from version 6.7.8 to current / latest (6.9.6). I tried to run the application to test the updates made in referring packages. I encountered following error: TypeInitializationException was unhandled An unhandled exception of type 'System.TypeInitializationException' occurred in Unknown Module. Additional information: The type initializer for '[Application Name]' threw an exception. Looking at this exception, it doesn't seems to be obvious what is going wrong here. There isn't even option for "View details". Many of you may get stuck on this and spent hours before you figure out that the AssemblyBinding.dependentAssembly.bindingRedirect are creating this » Read more

 Jsinh        

Did you encountered following exception / error when trying to run ASP.NET MVC web application? The view must derive from WebViewPage, or WebViewPage or Type 'ASP.PageViews_ViewStartcshtml' does not inherit from 'System.Web.WebPages.StartPage'. I encountered while I was playing with MVC 5 (applies to MVC 3 and 4 also) application. Every razor page should inherit from System.Web.Mvc.WebViewPage. You can resolve this issue by adding following line at the top in each view razor (*.cshtml) page: @inherits System.Web.Mvc.WebViewPage and add following line at the top of _ViewStart.cshtml : @inherits System.Web.Mvc.ViewStartPage or you can add a web.config file and add following (in root of Views folder where the Razor pages reside) <?xml version="1.0"?> <configuration> <configSections> <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web. » Read more

 Jsinh        

Note: [Deprecated Content] This was written while ASP.NET and .NET Core was in beta (around beta5 or beta6). Since then a lot of stuffs have changed and moved around. Stuffs described below may or may not be true for current stable releases of ASP.NET Core - Configuration feature. I recommend not to follow along and get confused. Use official configuration documentation that explains it correctly - docs.asp.net With the upcoming release of .NET 4.6 and ASP.NET 5 (currently in BETA phase) one namespace that is getting new look (re-written) is System.Configuration. If you have not already read then I recommend you to take a look at getting started post by Louis DeJardin - ASP.NET vNext Moving Parts: IConfiguration He has also explained other moving parts which are some interesting reads. Why you ask? Louis explains few reason why System.Configuration needs to » Read more

 Jsinh        

Note: [Deprecated Content] This was written while ASP.NET and .NET Core was in beta (around beta5 or beta6). Since then a lot of stuffs have changed and moved around. Stuffs described below may or may not be true for current stable releases of ASP.NET Core. I recommend not to follow along and get confused. Use official configuration documentation that explains it correctly - docs.asp.net ASP.NET 5 removed the web.config XML based configuration files and bring JSON based project.json and other similar files to maintain configuration related to your application. project.json is the main file that contains meta-information / configuration for running your ASP.NET 5 application. This JSON file consist of a node named compilationOptions which defines a child called languageVersion. Currently ASP.NET 5 only supports C# language. languageVersion can be one of the following options: It provides way to choose which » Read more

 Jsinh        

There are so many productive tools and packages out there that can be used for profiling an ASP.NET MVC application. While back I wrote a quick intro about how Glimpse can come handy profiling your web application. There is one more simplistic and quick way to start profiling load / execution time for your application routines using MiniProfiler. This little package is prepared by folks at Stackexchange and used for Stackoverflow.com and other sites. MiniProfile's homepage shows quick way to get started with using MiniProfiler in your application. Following code snippet is required to profile a piece of code (not to forget MiniProfiler.Start() and MiniProfiler.Stop()): var profiler = MiniProfiler.Current; using (profiler.Step("Set page title")) { // Your code to profile } and you will see something similar to following when you load your application and run through profiled piece of code: So if I need to profile the execution » Read more

 Jsinh        

Note: [Deprecated Content] This was written while ASP.NET and .NET Core was in beta (around beta5 or beta6). Since then a lot of stuffs have changed and moved around. Stuffs described below may or may not be true for current stable releases of ASP.NET Core. I recommend not to follow along and get confused. Use official configuration documentation that explains it correctly - docs.asp.net Along with the new version ASP.NET 5, comes some small goodies that are worth taking look at. One of those tiny but powerful enhancment currently experimented in ASP.NET 5 (still in BETA at the time of writing, may change) is the way to control exception / error detail displayed to end user and showing full stack trace and additional information when the developer is working. If you have given a try to the default template - "ASP.NET 5 Starter Web" » Read more

 Jsinh        

Please note: [Deprecated Content] This article is outdated now and lot of things have changed since it was written. Please refer / read to the newer version of the related article instead of the content below. Also follow along and learn about the latest bits on official ASP.NET Core documentation Thanks! In case you missed the big news, then its time to say 'Hey to K (KAY)' (i just made it up). Recently Microsoft announced .NET as Open Source with .NET 2015, ASP.NET 5 (vNext), ASP.NET Web Development on MAC and LINUX platform and the biggest of all Visual Studio IDE Community SKU (Visual Studio for Everyone - FREE). Leaving behind the closed group development practices and proprietary line of products, Microsoft is finally taking big step to embrace the open source way and community driven development. I feel very excited to see this happening already and » Read more

 Jsinh        

If you are not using Glimpse to debugging and profiling ASP.NET web application then you are missing out on very useful stuff I must say. This NuGet package brings many handy information about your ASP.NET MVC application, which in turn can be useful and quick help to dig state and performance issues in your application. Advantage of adapting Glimpse is that, it can be used in production environment where it can be enabled or visible based on your custom configuration / conditon. Thus gives you power to analyse your production state without compromising or hindering your environment rules and constraints. You can install Glimpse from NuGet into your ASP.NET MVC application with Install-Package Glimpse.Mvc5 (because I am using MVC5 for this example). This installs three packages: Glimpse.Mvc5 (Current release is 1.5.3) Glimpse.AspNet Glimpse (Core) If you are using other version of MVC you » Read more

 Jsinh        

Another application configuration setting you will observe in web.config of your ASP.NET MVC application is webpages:Version <add key="webpages:Version" value="3.0.0.0" /> The value for this setting currently is showing 3.0.0.0. This indicates the version of Webpages - Razor view engine is to be used. This application setting was introduced during update release of ASP.NET MVC 3 and is used to identify which Razor view engine to be used for handling webpages in your MVC application. Based on my digging into ASP.NET WebStack codebase on codeplex, Build and Revision component of version number are optional or can differ. If these two components of version number are not present or not found to be valid System.Web.WebPages.Deployment library fixes it to x.x.0.0 and returns the version number. What will happen if webpages:Version » Read more

 Jsinh        

If you open your web.config at root of your MVC project you will find bunch of default appsetting keys added by MVC or WebAPI. One of the appsetting with key webpapges:Enabled is added which as default value as false. So what is the deal with this appsetting? To find out the answer to this simple question I started searching ASP.NET WebStack codebase on codeplex. This appsetting is processed by the System.Web.WebPages.Deployment - WebPagesDeployment.cs code. Dry-running the code base I got answer to my query. Three possibility for the appsetting - webpages:Enabled: Key - value not added at all or not having a valid boolean value. Key - value added and set to false. Key - value added and set to true. Case 1: In this case when PreApplicationStartCode > Start method is called which in turn calls > StartCore which internaly checks this application » Read more

 Jsinh        

When creating a MVC project using Visual Studio you will observe that creation process will add two web.config files to your project. In root of the project folder. In the root of the Views folder in the project folder. Question: The web.config in the root of the project is natural and expected, but why MVC project contains a web.config files in the views folder? Answer: To quote wikipedia: A controller can send commands to the model to update the model's state (e.g., editing a document). It can also send commands to its associated view to change the view's presentation of the model (e.g., by scrolling through a document). In ASP.NET MVC concept of routing is used that helps decoupling URLs mapping with specific files. Due to the routing definitions and route collection definitions of any application enables the application to serve a URL to » Read more

 Jsinh        

Started to learn MVC and WebAPI from scratch, have been working with non-web stuffs (mostly protocols and win-service) for a very long time and just want to get my head around with the Modern Microsoft way to do web stuffs using ASP.NET MVC and / or WebAPI. So I decided to add my learning notes here as Modern ASP.NET (MAN - slug) blog post series so it can help other starters to jingle and mingle with web using ASP.NET MVC and / or WebAPI. Current version of ASP.NET MVC is 5.1 and ASP.NET WebAPI is 2.1 So to answer my own question: What makes the base for any ASP.NET MVC, ASP.NET WebAPI web application and what code base it stands on? ASP.NET MVC 5.1 I created a new ASP.NET project from Visual studio (.NET 4.5.1) and used "Empty" » Read more

 Jsinh