Tuesday 10 June 2014

ASP.NET vNext


Details of the new version of the ASP.NET have being announced. Additional details about it can be found over the Internet e.g. here. Since chances are high that many of the proposed changes should make it to the actual product in its current form or a modified form, I thought it would be a good idea to try out the new version.
I was a little surprised when I created a new web project in Visual Studio 2014 CTP - You can try it out too if you have an account on Azure, there is an VM image available in the Image Gallery by the name "Visual Studio Professional 14 CTP". Notable things are :
  1. There is no web.config. Much of the configuration in the web.config file used to target the hosting of application in IIS, IIS Express or Cassini. Now that ASP.NET vNext aims to break free from IIS (refer to "Helios"), much of it not needed anyways. Rest of the configuration can be specified in "config.json" file - yes, it contains a JSON object and Visual Studio does a neat job of helping us with Intellisense. By default it has a connectionstring that wires up the default connection to a database hosted on "(localdb)\mssqllocaldb".
  2. There are not many options available on the dialog box that opens up when you click "Properties" of the context menu of the web project. Most of it is moved into "project.json" file which stores (again) a JSON object. Apart from project properties, it also keeps a list of nuGet package references.
  3. There is an interesting reference in the project named ".NET Framework 4.5" - you are free to change it to ".NET Core Framework 4.5" though which is targeted towards hosting on cloud (read Azure). So, I guess in future we will not be required to install .NET framework on the target machine as the necessary framework assemblies will be available along with the application's deployment folder. I wonder how would that impact the GAC though.
  4. You can host an ASP.NET vNext application in IIS, IIS Express, or even self host it in a console application. Imagine taking your application in a USB and hosting it on any available laptop by just plugging the USB stick and launching a command file (which can produce by using Publish feature of ASP.NET vNext). As an experiment, I created an ASP.NET vNext Console application (named "ConsoleApp2") - added a class "startup.cs", updated "Program.cs" to start the web server and added a simple controller/view in the application : it works like a charm :)
  5. Default database model for authentication/authorization has been pruned to just 2 tables - AspNetUsers and AspNetUserClaims. AspNetUsers, as the name suggests, is about the users and their credentials. AspNetUserClaims is most probably targeted to store rest of the details like role etc. as a claim. It is much simpler and covers most of the bases.
  6. There is only one base class for controllers i.e. Controller. No ApiController or MvcController etc. In fact, you don't even need to do that if you want. e.g. You can add a POCO class like NonStandardController and add a public method (action) that returns whatever you want to return.
  7. Everything can be configured through "Configure" method of "Startup" class. e.g. DirectoryBrowsing can be enabled by invoking UseDirectoryBrowser method on IBuilder instance. In fact, there is a way to configure the ASP.NET application to use one (or more) middleware classes to return response. e.g.
     
 And here is how you register your own Middleware.
 
 
Note: Instead of writing code from scratch I referred to the code samples available at Entropy. It is a great place to start when experimenting with ASP.NET vNext.
 
 

1 comment:

  1. Thanks for sharing this nice post. It is really very good. Deploying your own version of .NET Best windows hosting will be able to give to support for the wide variety of scripting languages and the applications which are not available for any other platform. ASP and ASP.Net to develop dynamic web pages of your website. Before some days I visit myasp.net, here I found very good information about hosting.…. .

    ReplyDelete