Skip to main content


All About Pages In ASP.NET Core 2.0

I hope while working on Razor pages, one thing you have noticed is @page.  Let’s say you added a new page (named Sample.cshtml) in Visual Studio Code in your existing application. Once the page is added, we will get an empty editor window on the right side pane where we are going to write code for our page. In order to make things simple, I’m adding very simple HTML code:        <h1> Welcome to my page </h1>          Now, save the application and run. Oops 404! Any idea why we end up looking at such a weird page? Well, @page is holding this magic. Basically, none of the Razor pages will be considered as pages until and unless they are decorated as @page in the very first line. But as soon as we append the @page in our newly added Sample.cshtml page, things will work as expected. Next, we will quickly look at a few of the files which are added by default under a Pages folder with some pre-specified lines of code.

All About Appsettings.json in ASP.NET Core 2.0

As most of you are aware that in ASP.Net Core, we don't have anything called Web.Config, where we use to write our connection strings or application specific settings. Rather, here we have the file named appsettings.json to store similar sort of information. There are few very common use cases where we need to maintain multiple appsettings.json file in a single solution. For example: Multiple application settings per application - When we need to maintain different-different application specific settings based on the application environment. Say, one can have one type of application settings for Development, another type of application settings for Production, another one for Staging, and so on. Needless to mention, all the appsettings file will have different names. To implement inheritance – If there are some common settings between multiple application settings file, in that case developer can come up with a base application settings file and on top of that specific file

Application Initialization and Configuration in ASP.Net Versions

Most of us might have worked upon various versions of ASP.NET and few of you must be aware about the major changes happened in application initialization and configuration phase. In this article, I'll be outlining few of those major changes starting from ASP.NET MVC, ASP.NET Core 1.x and ASP.NET 2.x. In ASP.NET: In an era of ASP.NET (prior to ASP.NET Core releases), loading of the application was handled by IIS or say Inetmgr was the one who use to call web application's entry point wherein Global.asax.cs use to provide the Application_Start()method.Below is the sample code snippet take from file:        public class MvcApplication : System.Web.HttpApplication   {        protected void Application_Start()        {               AreaRegistration.RegisterAllAreas();               FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);               RouteConfig.RegisterRoutes(RouteTable.Routes);               BundleConfig.RegisterBundles(BundleTa

Tip on MVC URL Routing

Recently, one of my colleague asked me a question, in which his routing was not working as expected. Let me mention the exact URL he was giving: URL 1:  http://localhost:port/StudentEnquiries/StudentEnquiries/44" URL 2: http://localhost:port/StudentEnquiries/StudentEnquiries/?StudentID=44  And his code snippet was as below:            public class RouteConfig       {           public static void RegisterRoutes(RouteCollection routes)           {               routes.IgnoreRoute("{resource}.axd/{*pathInfo}");               routes.MapRoute(                   name: "Default",                   url: "{controller}/{action}/{id}",                   defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }               );           }       }      Where he claimed that he didn’t change anything in his Route.Config file and his Controller looks something like this:

Invoking web application from console application (.Net Core) via command prompt

In this article, I’ll be giving a walkthrough on how to create a console application and changing that into a web application. Or in other words, invoking a web application from a .Net core console application. And that too completely from command prompt. If you are a command prompt lover, you may love it. So, let’s gear up and proceed step-by-step. Verify .Net Core If you are creating a .Net Core application for the very first time, then it is good to verify whether it is installed on the system or not and this can be done by typing a simple command  dotnet --version  as shown below:   Create Console application Now we are sure that required setup is present on our machine, we can proceed and create our first Console application  using command dotnet new console as shown below:   On successful execution of above command, you will see that Program file and project file is created in your local directory and same can be verified by opening Program.