Skip to main content

Posts

Showing posts from April, 2018

All about Tag Helpers in ASP.NET Core 2.0

This time rather than jumping directly into the topic, let's have a look at the Login form code which you must have definitely seen while working on MVC application. What do you think about the above code snippet? Indeed, it works alright, but there are few problems with this. But the major problem is its a bit messy and difficult to read due to excessive use of @. So, now we have understood the problem, what is the solution? Here comes the Tag Helpers for our rescue. Let's quickly have a look at the code generated by the ASP.NET Core framework for the same functionality: The above code looks much cleaner. Isn’t it? If it looks interesting to you, we should learn more about it. What are Tag Helpers Tag Helpers are classes written in C# but are attached to HTML elements in order to run server-side code from Razor view. In other words, view created in HTML has its presentation logic defined in C#, which is ultimately executed on the w

Configure vs ConfigureServices in ASP.NET Core 2.0

Both words sound similar but there is a very thin line which differentiates these two. Let’s have a look at key differences between these two methods. Configure ConfigureServices Main purpose Does all the initial setup Does service configurations Default Location Resides in Startup.cs Resides in Startup.cs Execution sequence Hits prior to ConfigureServices Hits after Configure Ordering Order of steps mentioned in this method matters Order of the statements written to add services doesn’t matter HTTP request HTTP request first hits in this method                                  - Parameters Configure(IApplicationBuilder app, IHostingEnvironment env) ConfigureServices(IServiceCollection services) Middleware Setting up all the middleware are done in this method