Introduction to ASP.NET MVC6

Introduction

In an earlier article, Introduction to ASP.NET vNext, we learned about the next generation of ASP.NET called ASP.NET vNext.

One of the major changes happening in ASP.NET vNext is the changes happening in MVC. The next version of ASP.NET will come with MVC6 – where the Web API, MVC and Web Pages framework are merged into one framework. This new framework has been christened MVC6. With this new unified framework, we now have a unified controller and routing concepts. It is now possible to have a single controller that can return MVC views as well as Web API responses on the same HTTP verb.

MVC6 framework allows web developers to create both UI (using HTML) and web APIs.

To build web applications powered by ASP.NET MVC6, we need Visual Studio “14,” which is in preview at the moment and can be downloaded from http://go.microsoft.com/fwlink/p/?LinkId=400850

Overview of Model View Controller (MVC)

Here is a quick overview of MVC for readers who aren’t familiar with it.

Model-View-Controller is a pattern for building an UI, which divides software into three interconnected parts, (a) model  – consisting of application data, business rules, logic and functions; (b) view – this represents output; and (c) controller – which accepts inputs and converts it to commands for the model or view.

ASP.NET provides an alternate approach to the Web Forms approach for creating web applications.

ASP.NET MVC is lightweight, highly testable presentation framework that is defined in the System.Web.Mvc namespace and is a supported part of the System.Web namespace. It provides integration with ASP.NET features like master pages and membership-based applications.

Creating an ASP.NET vNext MVC6 Application

To create an MVC6 application, we can use Visual Studio “14,” CTP which can be downloaded from http://go.microsoft.com/fwlink/p/?LinkId=400850.

Once installed, create a new ASP.NET Application of type “ASP.NET vNext Empty Web application” titled MVC6Demo.

New Project
New Project

Once the project is created, you will notice two files:

1.       Project.json : which lists the dependencies.

The contents of the file should be as under:

{
    "dependencies": {
        "Helios" : "0.1-alpha-build-0585"
    },
    "configurations" : {
        "net45" : { },
        "k10" : { }
    }
}

                “Helios” refers to the ability for the application to run under IIS.

2.       Startup.cs: which represents the class where we will configure the HTTP request pipeline for the web application.

The contents of this should be as under:

using System;
using Microsoft.AspNet.Builder;
 
namespace MVC6Demo
{
    public class Startup
    {
        public void Configure(IBuilder app)
        {
            // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        }
    }
}

Once your project has been created, if you observe the output window, you will see a lot of activity. This is because Visual Studio loads missing dependencies asynchronously.

Output displayed in Output window

Restoring packages for c:\users\vipul\documents\visual studio 14\Projects\MVC6Demo\MVC6Demo\project.json
Attempting to resolve dependency MVC6Demo >= 1.0.0
Attempting to resolve dependency Helios >= 0.1-alpha-build-0585
  OPEN Helios.0.1-alpha-build-0585.nupkg
  OPEN Helios.0.1-alpha-build-0585\Helios.0.1-alpha-build-0585.nuspec
Attempting to resolve dependency mscorlib >=
Attempting to resolve dependency System >=
Attempting to resolve dependency System.Core >=
Attempting to resolve dependency Microsoft.CSharp >=
Attempting to resolve dependency MVC6Demo >= 1.0.0
Attempting to resolve dependency Helios >= 0.1-alpha-build-0585
Attempting to resolve dependency Microsoft.AspNet.Loader.IIS.Interop >= 0.1-alpha-build-0585
  OPEN Microsoft.AspNet.Loader.IIS.Interop.0.1-alpha-build-0585.nupkg
  OPEN Microsoft.AspNet.Loader.IIS.Interop.0.1-alpha-build-0585\Microsoft.AspNet.Loader.IIS.Interop.0.1-alpha-build-0585.nuspec
Attempting to resolve dependency Microsoft.AspNet.Loader.IIS.Interop >= 0.1-alpha-build-0585
Attempting to resolve dependency Microsoft.AspNet.Loader.IIS >= 0.1-alpha-build-0585
  OPEN Microsoft.AspNet.Loader.IIS.0.1-alpha-build-0585.nupkg
  OPEN Microsoft.AspNet.Loader.IIS.0.1-alpha-build-0585\Microsoft.AspNet.Loader.IIS.0.1-alpha-build-0585.nuspec
Attempting to resolve dependency Microsoft.AspNet.Loader.IIS >= 0.1-alpha-build-0585
Attempting to resolve dependency Microsoft.AspNet.FeatureModel >= 0.1-alpha-build-0444
  OPEN Microsoft.AspNet.FeatureModel.0.1-alpha-build-0444.nupkg
Attempting to resolve dependency Microsoft.AspNet.FeatureModel >= 0.1-alpha-build-0444
  OPEN Microsoft.AspNet.FeatureModel.0.1-alpha-build-0444\Microsoft.AspNet.FeatureModel.0.1-alpha-build-0444.nuspec
Attempting to resolve dependency Microsoft.AspNet.Hosting >= 0.1-alpha-build-0572
Attempting to resolve dependency Microsoft.AspNet.Hosting >= 0.1-alpha-build-0572
  OPEN Microsoft.AspNet.Hosting.0.1-alpha-build-0572.nupkg
  OPEN Microsoft.AspNet.Hosting.0.1-alpha-build-0572\Microsoft.AspNet.Hosting.0.1-alpha-build-0572.nuspec
Attempting to resolve dependency Microsoft.AspNet.Http >= 0.1-alpha-build-0444
Attempting to resolve dependency Microsoft.AspNet.Http >= 0.1-alpha-build-0444
  OPEN Microsoft.AspNet.Http.0.1-alpha-build-0444.nupkg
  OPEN Microsoft.AspNet.HttpFeature.0.1-alpha-build-0444.nupkg
  OPEN Microsoft.AspNet.Http.0.1-alpha-build-0444\Microsoft.AspNet.Http.0.1-alpha-build-0444.nuspec
  OPEN Microsoft.AspNet.HttpFeature.0.1-alpha-build-0444\Microsoft.AspNet.HttpFeature.0.1-alpha-build-0444.nuspec
Attempting to resolve dependency Microsoft.AspNet.PipelineCore >= 0.1-alpha-build-0444
Attempting to resolve dependency Microsoft.AspNet.PipelineCore >= 0.1-alpha-build-0444
  OPEN Microsoft.AspNet.PipelineCore.0.1-alpha-build-0444.nupkg
  OPEN Microsoft.AspNet.PipelineCore.0.1-alpha-build-0444\Microsoft.AspNet.PipelineCore.0.1-alpha-build-0444.nuspec
Attempting to resolve dependency Microsoft.AspNet.HttpFeature >= 0.1-alpha-build-0444
Attempting to resolve dependency Microsoft.AspNet.HttpFeature >= 0.1-alpha-build-0444
Attempting to resolve dependency Microsoft.Framework.Logging >= 0.1-alpha-build-0172
Attempting to resolve dependency Microsoft.Framework.Logging >= 0.1-alpha-build-0172
  OPEN Microsoft.Framework.Logging.0.1-alpha-build-0172.nupkg
  OPEN Microsoft.Framework.Logging.0.1-alpha-build-0172\Microsoft.Framework.Logging.0.1-alpha-build-0172.nuspec
  OPEN Microsoft.Framework.Logging.0.1-alpha-build-0172\Microsoft.Framework.Logging.0.1-alpha-build-0172.nuspec
Attempting to resolve dependency Microsoft.AspNet.Security.DataProtection >= 0.1-alpha-build-0153
Attempting to resolve dependency Microsoft.AspNet.Security.DataProtection >= 0.1-alpha-build-0153
  OPEN Microsoft.AspNet.Security.DataProtection.0.1-alpha-build-0153.nupkg
  OPEN Microsoft.AspNet.Security.DataProtection.0.1-alpha-build-0153.nupkg
  OPEN Microsoft.AspNet.Security.DataProtection.0.1-alpha-build-0153\Microsoft.AspNet.Security.DataProtection.0.1-alpha-build-0153.nuspec
  OPEN Microsoft.AspNet.Security.DataProtection.0.1-alpha-build-0153\Microsoft.AspNet.Security.DataProtection.0.1-alpha-build-0153.nuspec
Attempting to resolve dependency System.Console >= 4.0.0.0
Attempting to resolve dependency Microsoft.Framework.ConfigurationModel >= 0.1-alpha-build-0233
  OPEN Microsoft.Framework.ConfigurationModel.0.1-alpha-build-0233.nupkg
  OPEN Microsoft.Framework.ConfigurationModel.Json.0.1-alpha-build-0233.nupkg
  OPEN Microsoft.Framework.ConfigurationModel.Xml.0.1-alpha-build-0233.nupkg
  OPEN System.Console.4.0.0.0.nupkg
  OPEN Microsoft.Framework.ConfigurationModel.0.1-alpha-build-0233\Microsoft.Framework.ConfigurationModel.0.1-alpha-build-0233.nuspec
  OPEN Microsoft.Framework.ConfigurationModel.Json.0.1-alpha-build-0233\Microsoft.Framework.ConfigurationModel.Json.0.1-alpha-build-0233.nuspec
  OPEN Microsoft.Framework.ConfigurationModel.Xml.0.1-alpha-build-0233\Microsoft.Framework.ConfigurationModel.Xml.0.1-alpha-build-0233.nuspec
  OPEN System.Console.4.0.0.0\System.Console.4.0.0.0.nuspec
Attempting to resolve dependency System.Globalization.Extensions >= 4.0.0.0
Attempting to resolve dependency Microsoft.Framework.DependencyInjection >= 0.1-alpha-build-0389
  OPEN System.Globalization.Extensions.4.0.0.0.nupkg
  OPEN Microsoft.Framework.DependencyInjection.0.1-alpha-build-0389.nupkg
  OPEN Microsoft.Framework.DependencyInjection.Autofac.0.1-alpha-build-0389.nupkg
  OPEN Microsoft.Framework.DependencyInjection.Ninject.0.1-alpha-build-0389.nupkg
  OPEN Microsoft.Framework.DependencyInjection.StructureMap.0.1-alpha-build-0389.nupkg
  OPEN Microsoft.Framework.DependencyInjection.Unity.0.1-alpha-build-0389.nupkg
  OPEN Microsoft.Framework.DependencyInjection.Windsor.0.1-alpha-build-0389.nupkg
  OPEN System.Globalization.Extensions.4.0.0.0\System.Globalization.Extensions.4.0.0.0.nuspec
Attempting to resolve dependency Microsoft.Framework.ConfigurationModel >= 0.1-alpha-build-0233
  OPEN Microsoft.Framework.DependencyInjection.0.1-alpha-build-0389\Microsoft.Framework.DependencyInjection.0.1-alpha-build-0389.nuspec
  OPEN Microsoft.Framework.DependencyInjection.Autofac.0.1-alpha-build-0389\Microsoft.Framework.DependencyInjection.Autofac.0.1-alpha-build-0389.nuspec
  OPEN Microsoft.Framework.DependencyInjection.Ninject.0.1-alpha-build-0389\Microsoft.Framework.DependencyInjection.Ninject.0.1-alpha-build-0389.nuspec
  OPEN Microsoft.Framework.DependencyInjection.StructureMap.0.1-alpha-build-0389\Microsoft.Framework.DependencyInjection.StructureMap.0.1-alpha-build-0389.nuspec
  OPEN Microsoft.Framework.DependencyInjection.Unity.0.1-alpha-build-0389\Microsoft.Framework.DependencyInjection.Unity.0.1-alpha-build-0389.nuspec
  OPEN Microsoft.Framework.DependencyInjection.Windsor.0.1-alpha-build-0389\Microsoft.Framework.DependencyInjection.Windsor.0.1-alpha-build-0389.nuspec
Attempting to resolve dependency Microsoft.Framework.Runtime.Interfaces >= 0.1-alpha-build-0446
Attempting to resolve dependency Microsoft.Framework.DependencyInjection >= 0.1-alpha-build-0389
  OPEN Microsoft.Framework.Runtime.Interfaces.0.1-alpha-build-0446.nupkg
  OPEN Microsoft.Framework.Runtime.Interfaces.0.1-alpha-build-0446\Microsoft.Framework.Runtime.Interfaces.0.1-alpha-build-0446.nuspec
Attempting to resolve dependency System.ApplicationContext >= 4.0.0.0
  OPEN System.ApplicationContext.4.0.0.0.nupkg
  OPEN System.ApplicationContext.4.0.0.0\System.ApplicationContext.4.0.0.0.nuspec
Attempting to resolve dependency Microsoft.Framework.Runtime.Interfaces >= 0.1-alpha-build-0446
Attempting to resolve dependency Microsoft.Win32.Registry >= 4.0.0.0
  OPEN Microsoft.Win32.Registry.4.0.0.0.nupkg
  OPEN Microsoft.Win32.Registry.4.0.0.0\Microsoft.Win32.Registry.4.0.0.0.nuspec
Attempting to resolve dependency System.Collections >= 4.0.0.0
  OPEN System.Collections.4.0.0.0.nupkg
  OPEN System.Collections.Concurrent.4.0.0.0.nupkg
  OPEN System.Collections.NonGeneric.4.0.0.0.nupkg
  OPEN System.Collections.Specialized.4.0.0.0.nupkg
  OPEN System.Collections.4.0.0.0\System.Collections.4.0.0.0.nuspec
  OPEN System.Collections.Concurrent.4.0.0.0\System.Collections.Concurrent.4.0.0.0.nuspec
  OPEN System.Collections.NonGeneric.4.0.0.0\System.Collections.NonGeneric.4.0.0.0.nuspec
  OPEN System.Collections.Specialized.4.0.0.0\System.Collections.Specialized.4.0.0.0.nuspec
Attempting to resolve dependency System.Collections.Concurrent >= 4.0.0.0
Attempting to resolve dependency System.ComponentModel >= 4.0.0.0
  OPEN System.ComponentModel.4.0.0.0.nupkg
  OPEN System.ComponentModel.EventBasedAsync.4.0.0.0.nupkg
  OPEN System.ComponentModel.4.0.0.0\System.ComponentModel.4.0.0.0.nuspec
  OPEN System.ComponentModel.EventBasedAsync.4.0.0.0\System.ComponentModel.EventBasedAsync.4.0.0.0.nuspec
Attempting to resolve dependency System.Diagnostics.Debug >= 4.0.10.0
  OPEN System.Diagnostics.Debug.4.0.10.0.nupkg
  OPEN System.Diagnostics.Debug.4.0.10.0\System.Diagnostics.Debug.4.0.10.0.nuspec
Attempting to resolve dependency System.Diagnostics.Process >= 4.0.0.0
  OPEN System.Diagnostics.Process.4.0.0.0.nupkg
  OPEN System.Diagnostics.Process.4.0.0.0\System.Diagnostics.Process.4.0.0.0.nuspec
Attempting to resolve dependency System.Diagnostics.Tools >= 4.0.0.0
  OPEN System.Diagnostics.Tools.4.0.0.0.nupkg
  OPEN System.Diagnostics.Tools.4.0.0.0\System.Diagnostics.Tools.4.0.0.0.nuspec
Attempting to resolve dependency System.Globalization >= 4.0.10.0
  OPEN System.Globalization.4.0.10.0.nupkg
  OPEN System.Globalization.Calendars.4.0.0.0.nupkg
  OPEN System.Globalization.4.0.10.0\System.Globalization.4.0.10.0.nuspec
  OPEN System.Globalization.Calendars.4.0.0.0\System.Globalization.Calendars.4.0.0.0.nuspec
Attempting to resolve dependency System.IO >= 4.0.0.0
  OPEN System.IO.4.0.0.0.nupkg
  OPEN System.IO.Compression.4.0.0.0.nupkg
  OPEN System.IO.FileSystem.4.0.10.0.nupkg
  OPEN System.IO.FileSystem.Primitives.4.0.20.0.nupkg
  OPEN System.IO.FileSystem.Watcher.4.0.0.0.nupkg
  OPEN System.IO.4.0.0.0\System.IO.4.0.0.0.nuspec
  OPEN System.IO.Compression.4.0.0.0\System.IO.Compression.4.0.0.0.nuspec
  OPEN System.IO.FileSystem.4.0.10.0\System.IO.FileSystem.4.0.10.0.nuspec
  OPEN System.IO.FileSystem.Primitives.4.0.20.0\System.IO.FileSystem.Primitives.4.0.20.0.nuspec
  OPEN System.IO.FileSystem.Watcher.4.0.0.0\System.IO.FileSystem.Watcher.4.0.0.0.nuspec
Attempting to resolve dependency System.IO.FileSystem >= 4.0.10.0
Attempting to resolve dependency System.IO.FileSystem.Primitives >= 4.0.20.0
Attempting to resolve dependency System.Linq >= 4.0.0.0
  OPEN System.Linq.4.0.0.0.nupkg
  OPEN System.Linq.Expressions.4.0.0.0.nupkg
  OPEN System.Linq.Parallel.4.0.0.0.nupkg
  OPEN System.Linq.Queryable.4.0.0.0.nupkg
  OPEN System.Linq.4.0.0.0\System.Linq.4.0.0.0.nuspec
  OPEN System.Linq.Expressions.4.0.0.0\System.Linq.Expressions.4.0.0.0.nuspec
  OPEN System.Linq.Parallel.4.0.0.0\System.Linq.Parallel.4.0.0.0.nuspec
  OPEN System.Linq.Queryable.4.0.0.0\System.Linq.Queryable.4.0.0.0.nuspec
Attempting to resolve dependency System.Net.NetworkInformation >= 4.0.10.0
  OPEN System.Net.NetworkInformation.4.0.10.0.nupkg
  OPEN System.Net.NetworkInformation.4.0.10.0\System.Net.NetworkInformation.4.0.10.0.nuspec
Attempting to resolve dependency System.Net.Primitives >= 4.0.10.0
  OPEN System.Net.Primitives.4.0.10.0.nupkg
  OPEN System.Net.Primitives.4.0.10.0\System.Net.Primitives.4.0.10.0.nuspec
Attempting to resolve dependency System.Reflection >= 4.0.10.0
  OPEN System.Reflection.4.0.10.0.nupkg
  OPEN System.Reflection.Emit.4.0.0.0.nupkg
  OPEN System.Reflection.Emit.ILGeneration.4.0.0.0.nupkg
  OPEN System.Reflection.Emit.Lightweight.4.0.0.0.nupkg
  OPEN System.Reflection.Extensions.4.0.0.0.nupkg
  OPEN System.Reflection.Primitives.4.0.0.0.nupkg
  OPEN System.Reflection.TypeExtensions.4.0.0.0.nupkg
  OPEN System.Reflection.4.0.10.0\System.Reflection.4.0.10.0.nuspec
  OPEN System.Reflection.Emit.4.0.0.0\System.Reflection.Emit.4.0.0.0.nuspec
  OPEN System.Reflection.Emit.ILGeneration.4.0.0.0\System.Reflection.Emit.ILGeneration.4.0.0.0.nuspec
  OPEN System.Reflection.Emit.Lightweight.4.0.0.0\System.Reflection.Emit.Lightweight.4.0.0.0.nuspec
  OPEN System.Reflection.Extensions.4.0.0.0\System.Reflection.Extensions.4.0.0.0.nuspec
  OPEN System.Reflection.Primitives.4.0.0.0\System.Reflection.Primitives.4.0.0.0.nuspec
  OPEN System.Reflection.TypeExtensions.4.0.0.0\System.Reflection.TypeExtensions.4.0.0.0.nuspec
Attempting to resolve dependency System.Reflection.TypeExtensions >= 4.0.0.0
Attempting to resolve dependency System.Reflection.Primitives >= 4.0.0.0
Attempting to resolve dependency System.Resources.ResourceManager >= 4.0.0.0
  OPEN System.Resources.ResourceManager.4.0.0.0.nupkg
  OPEN System.Resources.ResourceManager.4.0.0.0\System.Resources.ResourceManager.4.0.0.0.nuspec
Attempting to resolve dependency System.Runtime >= 4.0.20.0
  OPEN System.Runtime.4.0.20.0.nupkg
  OPEN System.Runtime.Extensions.4.0.10.0.nupkg
  OPEN System.Runtime.Handles.4.0.0.0.nupkg
  OPEN System.Runtime.InteropServices.4.0.20.0.nupkg
  OPEN System.Runtime.Loader.4.0.0.0.nupkg
  OPEN System.Runtime.Numerics.4.0.0.0.nupkg
  OPEN System.Runtime.Serialization.Primitives.4.0.0.0.nupkg
  OPEN System.Runtime.4.0.20.0\System.Runtime.4.0.20.0.nuspec
  OPEN System.Runtime.Extensions.4.0.10.0\System.Runtime.Extensions.4.0.10.0.nuspec
  OPEN System.Runtime.Handles.4.0.0.0\System.Runtime.Handles.4.0.0.0.nuspec
  OPEN System.Runtime.InteropServices.4.0.20.0\System.Runtime.InteropServices.4.0.20.0.nuspec
  OPEN System.Runtime.Loader.4.0.0.0\System.Runtime.Loader.4.0.0.0.nuspec
  OPEN System.Runtime.Numerics.4.0.0.0\System.Runtime.Numerics.4.0.0.0.nuspec
  OPEN System.Runtime.Serialization.Primitives.4.0.0.0\System.Runtime.Serialization.Primitives.4.0.0.0.nuspec
Attempting to resolve dependency System.Runtime.Extensions >= 4.0.10.0
Attempting to resolve dependency System.Runtime.Handles >= 4.0.0.0
Attempting to resolve dependency System.Runtime.InteropServices >= 4.0.20.0
Attempting to resolve dependency System.Security.Claims >= 0.1-alpha-build-0286
  OPEN System.Security.Claims.0.1-alpha-build-0286.nupkg
  OPEN System.Security.Claims.0.1-alpha-build-0286\System.Security.Claims.0.1-alpha-build-0286.nuspec
Attempting to resolve dependency System.Diagnostics.Contracts >= 4.0.0.0
  OPEN System.Diagnostics.Contracts.4.0.0.0.nupkg
  OPEN System.Diagnostics.Contracts.4.0.0.0\System.Diagnostics.Contracts.4.0.0.0.nuspec
Attempting to resolve dependency System.Security.Cryptography >= 4.0.0.0
  OPEN System.Security.Cryptography.4.0.0.0.nupkg
  OPEN System.Security.Cryptography.DeriveBytes.4.0.0.0.nupkg
  OPEN System.Security.Cryptography.Encoding.4.0.0.0.nupkg
  OPEN System.Security.Cryptography.Encryption.Aes.4.0.0.0.nupkg
  OPEN System.Security.Cryptography.Encryption.RSA.4.0.0.0.nupkg
  OPEN System.Security.Cryptography.HashAlgorithms.MD5.4.0.0.0.nupkg
  OPEN System.Security.Cryptography.HashAlgorithms.SHA1.4.0.0.0.nupkg
  OPEN System.Security.Cryptography.HashAlgorithms.SHA2.4.0.0.0.nupkg
  OPEN System.Security.Cryptography.RandomNumberGenerator.4.0.0.0.nupkg
  OPEN System.Security.Cryptography.X509Certificates.4.0.0.0.nupkg
  OPEN System.Security.Cryptography.4.0.0.0\System.Security.Cryptography.4.0.0.0.nuspec
  OPEN System.Security.Cryptography.DeriveBytes.4.0.0.0\System.Security.Cryptography.DeriveBytes.4.0.0.0.nuspec
  OPEN System.Security.Cryptography.Encoding.4.0.0.0\System.Security.Cryptography.Encoding.4.0.0.0.nuspec
  OPEN System.Security.Cryptography.Encryption.Aes.4.0.0.0\System.Security.Cryptography.Encryption.Aes.4.0.0.0.nuspec
  OPEN System.Security.Cryptography.Encryption.RSA.4.0.0.0\System.Security.Cryptography.Encryption.RSA.4.0.0.0.nuspec
  OPEN System.Security.Cryptography.HashAlgorithms.MD5.4.0.0.0\System.Security.Cryptography.HashAlgorithms.MD5.4.0.0.0.nuspec
  OPEN System.Security.Cryptography.HashAlgorithms.SHA1.4.0.0.0\System.Security.Cryptography.HashAlgorithms.SHA1.4.0.0.0.nuspec
  OPEN System.Security.Cryptography.HashAlgorithms.SHA2.4.0.0.0\System.Security.Cryptography.HashAlgorithms.SHA2.4.0.0.0.nuspec
  OPEN System.Security.Cryptography.RandomNumberGenerator.4.0.0.0\System.Security.Cryptography.RandomNumberGenerator.4.0.0.0.nuspec
  OPEN System.Security.Cryptography.X509Certificates.4.0.0.0\System.Security.Cryptography.X509Certificates.4.0.0.0.nuspec
Attempting to resolve dependency System.Security.Cryptography.X509Certificates >= 4.0.0.0
Attempting to resolve dependency System.Security.SecureString >= 4.0.0.0
  OPEN System.Security.SecureString.4.0.0.0.nupkg
  OPEN System.Security.SecureString.4.0.0.0\System.Security.SecureString.4.0.0.0.nuspec
Attempting to resolve dependency System.Security.Cryptography.Encoding >= 4.0.0.0
Attempting to resolve dependency System.Security.Principal >= 4.0.0.0
  OPEN System.Security.Principal.4.0.0.0.nupkg
  OPEN System.Security.Principal.4.0.0.0\System.Security.Principal.4.0.0.0.nuspec
Attempting to resolve dependency System.Text.Encoding >= 4.0.20.0
  OPEN System.Text.Encoding.4.0.20.0.nupkg
  OPEN System.Text.Encoding.Extensions.4.0.10.0.nupkg
  OPEN System.Text.Encoding.4.0.20.0\System.Text.Encoding.4.0.20.0.nuspec
  OPEN System.Text.Encoding.Extensions.4.0.10.0\System.Text.Encoding.Extensions.4.0.10.0.nuspec
Attempting to resolve dependency System.Text.Encoding.Extensions >= 4.0.10.0
Attempting to resolve dependency System.Threading >= 4.0.0.0
  OPEN System.Threading.4.0.0.0.nupkg
  OPEN System.Threading.ExecutionContext.4.0.0.0.nupkg
  OPEN System.Threading.Overlapped.4.0.0.0.nupkg
  OPEN System.Threading.Tasks.4.0.10.0.nupkg
  OPEN System.Threading.Tasks.Parallel.4.0.0.0.nupkg
  OPEN System.Threading.Thread.4.0.0.0.nupkg
  OPEN System.Threading.ThreadPool.4.0.10.0.nupkg
  OPEN System.Threading.Timer.4.0.0.0.nupkg
  OPEN System.Threading.4.0.0.0\System.Threading.4.0.0.0.nuspec
  OPEN System.Threading.ExecutionContext.4.0.0.0\System.Threading.ExecutionContext.4.0.0.0.nuspec
  OPEN System.Threading.Overlapped.4.0.0.0\System.Threading.Overlapped.4.0.0.0.nuspec
  OPEN System.Threading.Tasks.4.0.10.0\System.Threading.Tasks.4.0.10.0.nuspec
  OPEN System.Threading.Tasks.Parallel.4.0.0.0\System.Threading.Tasks.Parallel.4.0.0.0.nuspec
  OPEN System.Threading.Thread.4.0.0.0\System.Threading.Thread.4.0.0.0.nuspec
  OPEN System.Threading.ThreadPool.4.0.10.0\System.Threading.ThreadPool.4.0.10.0.nuspec
  OPEN System.Threading.Timer.4.0.0.0\System.Threading.Timer.4.0.0.0.nuspec
Attempting to resolve dependency System.Threading.ExecutionContext >= 4.0.0.0
Attempting to resolve dependency System.Threading.Tasks >= 4.0.10.0
Attempting to resolve dependency System.Threading.ThreadPool >= 4.0.10.0
Resolving complete, 6492ms elapsed
Installing Helios 0.1-alpha-build-0585
Installing Microsoft.AspNet.Loader.IIS.Interop 0.1-alpha-build-0585
Installing Microsoft.AspNet.Loader.IIS 0.1-alpha-build-0585
Installing Microsoft.AspNet.FeatureModel 0.1-alpha-build-0444
Installing Microsoft.AspNet.Hosting 0.1-alpha-build-0572
Installing Microsoft.Framework.Logging 0.1-alpha-build-0172
Installing Microsoft.AspNet.PipelineCore 0.1-alpha-build-0444
Installing Microsoft.AspNet.Http 0.1-alpha-build-0444
Installing Microsoft.AspNet.HttpFeature 0.1-alpha-build-0444
Installing Microsoft.AspNet.Security.DataProtection 0.1-alpha-build-0153
Installing Microsoft.Framework.ConfigurationModel 0.1-alpha-build-0233
Installing Microsoft.Framework.Runtime.Interfaces 0.1-alpha-build-0446
Installing Microsoft.Framework.DependencyInjection 0.1-alpha-build-0389
Installing System.Console 4.0.0.0
Installing System.Globalization.Extensions 4.0.0.0
Installing System.ApplicationContext 4.0.0.0
Installing System.Collections.Concurrent 4.0.0.0
Installing Microsoft.Win32.Registry 4.0.0.0
Installing System.Collections 4.0.0.0
Installing System.ComponentModel 4.0.0.0
Installing System.Diagnostics.Debug 4.0.10.0
Installing System.Diagnostics.Process 4.0.0.0
Installing System.Diagnostics.Tools 4.0.0.0
Installing System.Globalization 4.0.10.0
Installing System.IO 4.0.0.0
Installing System.IO.FileSystem 4.0.10.0
Installing System.IO.FileSystem.Primitives 4.0.20.0
Installing System.Linq 4.0.0.0
Installing System.Net.NetworkInformation 4.0.10.0
Installing System.Net.Primitives 4.0.10.0
Installing System.Reflection 4.0.10.0
Installing System.Reflection.Primitives 4.0.0.0
Installing System.Reflection.TypeExtensions 4.0.0.0
Installing System.Resources.ResourceManager 4.0.0.0
Installing System.Runtime 4.0.20.0
Installing System.Runtime.Extensions 4.0.10.0
Installing System.Runtime.Handles 4.0.0.0
Installing System.Runtime.InteropServices 4.0.20.0
Installing System.Security.Claims 0.1-alpha-build-0286
Installing System.Diagnostics.Contracts 4.0.0.0
Installing System.Security.Cryptography 4.0.0.0
Installing System.Security.SecureString 4.0.0.0
Installing System.Security.Cryptography.X509Certificates 4.0.0.0
Installing System.Security.Cryptography.Encoding 4.0.0.0
Installing System.Security.Principal 4.0.0.0
Installing System.Text.Encoding 4.0.20.0
Installing System.Text.Encoding.Extensions 4.0.10.0
Installing System.Threading 4.0.0.0
Installing System.Threading.ExecutionContext 4.0.0.0
Installing System.Threading.Tasks 4.0.10.0
Installing System.Threading.ThreadPool 4.0.10.0
Restore complete, 9805ms elapsed

Now, we will add a package to the project and configure the Startup class to enable MVC.

 Change the contents of projects.json as shown below (changes highlighted):

{
    "dependencies": {
        "Helios": "0.1-alpha-build-0585",
        "Microsoft.AspNet.Mvc": ""
    },
    "configurations": {
        "net45": { },
        "k10": { }
    }
}

You will notice more activity in the Output window as Visual Studio downloads the required dependencies.

Make the following changes in Startup.cs to configure MVC.

using System;
using Microsoft.AspNet.Builder;
using Microsoft.Framework.DependencyInjection;
namespace MVC6Demo
{
    public class Startup
    {
        public void Configure(IBuilder app)
        {
            // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
            app.UseServices(services =>
            {
                // add the MVC framework into Dependency injection system. 
                services.AddMvc();
            });
            // This will configure MVC default settings like routes, etc. 
            app.UseMvc();
 
        }
    }
}

Next, we will create an MVC Controller class.

Add a new folder in the solution called Controllers and then right-click on the folder name in Solution Explore and select Add-> New Item and choose MVC Controller class and click Add.

Add MVC Controller Class
Add MVC Controller Class

Next, we will create a View class. To do that, we will first add a folder called Views and a sub-folder called Home. Then, Right-click on the folder name in Solution Explorer and select Add-> New Item and choose MVC5 View Page and click Add.

Add MVC5 View Page
Add MVC5 View Page

Change the default contents of the index.cshtml file as shown below (changes are highlighted).

@*
    For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
// Layout = "/Views/Shared/_Layout.cshtml";
// ViewBag.Title = "Home Page";
}
 
Authenticated User (true/false): @System.Security.Principal.WindowsPrincipal.Current.Identity.IsAuthenticated.ToString()

If we run the project now, we will get a browser showing the following:

Browser Showing Authenticated User: False
Browser Showing Authenticated User: False

The above was a simple demonstration of how to build a very simple ASP.NET vNext application running MVC6.

Summary

In this article, we learned how to build a very simple ASP.NET vNext application running MVC6.  I hope you have found this information useful.

References

http://en.wikipedia.org/wiki/Model-view-controller

http://www.asp.net/vnext/overview/aspnet-vnext/overview

http://blogs.msdn.com/b/dotnet/archive/2014/05/12/the-next-generation-of-net-asp-net-vnext.aspx

http://www.asp.net/vnext

About the author

Vipul Patel is a Program Manager currently working at Amazon Corporation. He has formerly worked at Microsoft in the Lync team and in the .NET team (in the Base Class libraries and the Debugging and Profiling team). He can be reached at vipul.patel@hotmail.com

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read