Skip to main content

Posts

Showing posts with the label ASP.NET Core 1.0

Reading version information from project.json

As of now, many of you are aware about the information stored in project.json file in ASP.NET Core 1.0. My this blog post will tell, how to retrieve the version number from project.json file. Below is the screenshot of my json file: And below is the code to get the version number: public void Configure( IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { // Reading project.json file var projConfig = new ConfigurationBuilder ().AddJsonFile( "project.json" ).Build(); //app version number var appVersion = projConfig[ "version" ]; // SQL Server version number var sqlServerVersion = projConfig[ "dependencies:EntityFramework.MicrosoftSqlServer" ]; } Hope this post was helpful.

Application State in ASP.NET Core 1.0

Introduction to Application State Application state provides a way to store in-memory data, which are smaller in size. It includes both global and user-specific data. Such data can be used across application and can be used by all users. Prior to ASP.NET Core 1.0 also there were Application and Session state options available to store such sort of data. Ways of managing Application State? Now question is, which state storage provider is to be used and when? It is influenced by variety of factors: Size of data Format of data Duration to persist data Sensitivity of data, etc. Based on your answers, Application State can be managed in variety of ways like: HTTPContext Cookies Session Querystring and Post Cache Other options (EF, Azure Table Storage, etc.) As part of ASP.NET Core 1.0 release, there is change in HTTPContext object. Hence I’ll emphasis on that. HTTPContext: Items collection of HTTPContext is used to store data which is required...

Consuming Services in ASP.NET Core MVC View

In continuation to my previous post entitled 'Consuming Services in ASP.NET Core Controller' on injecting services in controller, this time I'm writing on how to inject services directly in MVC View. In order to achieve this, a new keyword @inject is used. Here I'm not writing entire code again as it can be referred from my previous article. Let's register the service in ConfigureServices method as: public void ConfigureServices( IServiceCollection services) { ... ... services.AddTransient<IGUIDService,GUIDService>(); } Next is to inject service inside a View as: @inject IGUIDService guidService Now service is injected and available for use. Let's quickly use it: @ using CustomTagHelper.Services; @ inject IGUIDService guidService <p>@guidService.GenerateGUID()</p> Run your application and you will be able to see the required output as: Hope you enjoyed learnin...

Tag Helpers in ASP.NET Core 1.0

Exclusive Amazon Deals This article is for those who would like to use Tag Helpers over old Razor/HTML helpers. Tag Helpers, another new feature of ASP.NET Core. Let’s quickly have a look at it. What are Tag Helpers? As per ASP.NET documentation:                     " Tag Helpers enable server-side code to participate in creating and rendering HTML elements in Razor files ". Tag Helpers are somewhat similar to HTML Helpers/Razor Helpers introduced in previous version of ASP.NET MVC but those helpers were not that easy to understand for web designers because of inline C# method calls. As web designers are more inclined towards HTML, a simpler and comfortable approach was required. Fortunately, ASP.NET Core 1.0 provided that. Now one need not to use HTML Helpers to build cshtml forms. Means when you had to write this: Now you can write this: As you can see a bov...

Handling 404 Error for Unknown File Extensions in ASP.NET Core 1.0

In my previous article, I already briefed about Static Files in ASP.NET Core. Now let’s move bit further and know about how ASP.NET treats content files which are of unknown type for any browser. You might be aware that ASP.NET Core middleware serves only those content files which falls under known content types. As of now, it defines close to 400 known file content types. Now question is, how browser will respond to unknown content type files? Let’s understand it better with an example. I’m having an image file named SampleData with extension as .shweta. Here shweta is my custom extension and browser has no information about it. Browser has no idea about how to render this type of file. Please note, this is a static resource placed on wwwroot and has to be served to client. Now quickly open SampleData.shweta in browser and see what happens?           Uhh! This is HTTP 404 Not Found L But is this message correct? If you will go back and cr...

Fixing ‘DNX design time process error in VS 2015’

Exclusive Amazon Deals Today I thought to create my first demo using Visual Studio 2015 for ASP.NET Core 1.0. So, I opened VS2015 and chose Web Application template under ASP.NET 5 Templates. Visual Studio started creating a project for me. Although my project was created but at the same time some DNX error was thrown as shown below:                     I tried various options including restarting machine, re-installing Visual Studio, etc. But Alas ! Nothing worked. But on surfing for few hours, I found a solution which worked for me. You can run any of the below commands: dnvm update-self OR dnvm upgrade   Open Visual Studio 2015 and do dnvm update using command line as:     Once this command was executed, I didn’t get that error again. Hope reading this blog will save your few minutes of troubleshooting. Enjoy learning.

Features of ASP.NET Core 1.0

Exclusive Amazon Deals ASP.NET Core 1.0 is a new open-source framework for building modern Web applications. As compared to previous versions of ASP.NET there are many major changes happened. I’ll try to capture most of the changes in this blog post. ASP.NET Core 1.0 was initially named as ASP.NET 5. I’m dedicating this blog post to showcase the major features of ASP.NET Core 1.0. Single aligned web stack ASP.NET Core 1.0 is a single aligned web stack on top of ASP.NET for Web API and Web UI as shown in below figure (image taken from mva):   Above figure clearly depicts that there is very less sharing between these three stacks. If you will see from ASP.NET template view, you will notice that all the three options are dimmed out as shown below: Much leaner framework with reduced surface area ASP.NET Core 1.0 is no longer based on System.Web.dll. As per dzone , typical HTTPContext object graph takes 30K in memory while new implementation takes ar...