ASP.NET Core – Project Layout

ASP.NET Core – Project Layout ”; Previous Next In this chapter, we will discuss how ASP.NET core project appears on the file system and how the different files and directories all work together. Let us open the FirstAppDemo project created in the previous chapter. In the Solution Explorer window, right-click on the Solution node and select the Open Folder in File Explorer. You will see now the root directory with two files in it: FirstAppDemo.sln and global.json. FirstAppDemo.sln is a solution file. Visual Studio has used this extension for years by default, and you can double-click on the file if you want to open the app in Studio and work on it. There is also a global.json file. Let us open this file in Visual Studio. In the file, the project”s setting is significant. This project setting tells ASP.NET where to look for your source code and what folders contain your projects. There are two possible folders “src” for source and a “test” folder. Unless your projects and source code are in one of these two folders, the code won”t be available to build. You can change these settings if you want. The Windows Explorer has the “src” folder on disk. You don”t have a test folder. In the test folder, you could place your unit testing projects. Let us double-click on the “src” folder. You can see the FirstAppDemo project, and the web application. Now, double-click on the folder. These are the source code files for the application and you can also see this folder structure in the Solution Explorer window. This is because in the present version of ASP.NET Core, the file system determines what is in your project. If you add a new file to the disk, the file will be added to the project. If you delete a file, the file is removed from the project. Everything stays in sync and that is a little bit different than previous versions of ASP.NET Core where a project file, a *.cs proj file, that contained a manifest of everything that is in the project. ASP.NET Core also compiles your application when a file changes or a new file appears. Example Let us see a simple example by opening the Startup.cs file in the text editor. It is this line of code that responds to every HTTP request to your application and it simply responds with Hello World! Let us change the string in the above screenshot by saying “Hello World! This ASP.NET Core Application” as shown in the following program. using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; namespace FirstAppDemo { public class Startup { // This method gets called by the runtime. // Use this method to add services to the container. // For more information on how to configure your application, // visit http://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { } // This method gets called by the runtime. // Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(); if (env.IsDevelopment()){ app.UseDeveloperExceptionPage(); } app.Run(async (context) => { await context.Response.WriteAsync( “Hello World! This ASP.NET Core Application”); }); } } } Save this file in the text editor by pressing Ctrl + S and then go back to the web browser and refresh the application. You can now see that your changes are reflected in the browser. This is because ASP.NET will monitor the file system and automatically recompile the application when a file changes. You don”t need to explicitly build the application in Visual Studio. In fact, you can use a completely different editor, something like Visual Studio Code. All you need to do with the Visual Studio is get the web server started by running without the debugger. You can also press Ctrl + F5, and can edit files, save files, and just refresh the browser to see the changes. This is a nice workflow for building web applications with a compiled language like C#. Print Page Previous Next Advertisements ”;

ASP.NET Core – Overview

ASP.NET Core – Overview ”; Previous Next ASP.NET Core is the new web framework from Microsoft. It has been redesigned from the ground up to be fast, flexible, modern, and work across different platforms. Moving forward, ASP.NET Core is the framework that can be used for web development with .NET. If you have any experience with MVC or Web API over the last few years, you will notice some familiar features. At the end this tutorial, you will have everything you need to start using ASP.NET Core and write an application that can create, edit, and view data from a database. A Brief History of ASP.NET ASP.NET has been used from many years to develop web applications. Since then, the framework went through a steady evolutionary change and finally led us to its most recent descendant ASP.NET Core 1.0. ASP.NET Core 1.0 is not a continuation of ASP.NET 4.6. It is a whole new framework, a side-by-side project which happily lives alongside everything else we know. It is an actual re-write of the current ASP.NET 4.6 framework, but much smaller and a lot more modular. Some people think that many things remain the same, but this is not entirely true. ASP.NET Core 1.0 is a big fundamental change to the ASP.NET landscape. What is ASP.NET Core ASP.NET Core is an open source and cloud-optimized web framework for developing modern web applications that can be developed and run on Windows, Linux and the Mac. It includes the MVC framework, which now combines the features of MVC and Web API into a single web programming framework. ASP.NET Core apps can run on .NET Core or on the full .NET Framework. It was architected to provide an optimized development framework for apps that are deployed to the cloud or run on-premises. It consists of modular components with minimal overhead, so you retain flexibility while constructing your solutions. You can develop and run your ASP.NET Core apps cross-platform on Windows, Mac and Linux. Advantages of ASP.NET Core ASP.NET Core comes with the following advantages − ASP.NET Core has a number of architectural changes that result in a much leaner and modular framework. ASP.NET Core is no longer based on System.Web.dll. It is based on a set of granular and well factored NuGet packages. This allows you to optimize your app to include just the NuGet packages you need. The benefits of a smaller app surface area include tighter security, reduced servicing, improved performance, and decreased costs With ASP.NET Core, you can get the following improvements − Build and run cross-platform ASP.NET apps on Windows, Mac and Linux. Built on .NET Core, which supports true side-by-side app versioning. New tooling that simplifies modern Web development. Single aligned web stack for Web UI and Web APIs. Cloud-ready environment-based configuration. Built-in support for dependency injection. Tag Helpers which makes Razor markup more natural with HTML. Ability to host on IIS or self-host in your own process. Print Page Previous Next Advertisements ”;

ASP.NET Core – Home

ASP.NET Core Tutorial PDF Version Quick Guide Resources Job Search Discussion ASP.NET Core is the new web framework from Microsoft. ASP.NET Core is the framework you want to use for web development with .NET. At the end this tutorial, you will have everything you need to start using ASP.NET Core and write an application that can create, edit, and view data from a database. Audience This tutorial is designed for software programmers who would like to learn the basics of ASP.NET Core from scratch. Prerequisites You should have a basic understanding of Computer Programming terminologies. A basic understanding of any of the programming languages is a plus. Print Page Previous Next Advertisements ”;

ASP.NET Core – Configuration

ASP.NET Core – Configuration ”; Previous Next In this chapter, we will be discussing the configuration related to ASP.NET Core project. In Solution Explorer, you will see the Startup.cs file. If you have worked with previous versions of ASP.NET Core, you will probably expect to see a global.asax file, which was one place where you could write codes to execute during startup of a web application. You would also expect to see a web.config file containing all the configuration parameters your application needed to execute. In ASP.NET Core those files are all gone, and instead of configuration and startup code are loaded from Startup.cs. There is a Startup class inside the file and in this class you can configure your application and even configure your configuration sources. Here is the default implementation in the Startup.cs file. using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; namespace FirstAppDemo { public class Startup { // This method gets called by the runtime. // Use this method to add services to the container. // For more information on how to configure your application, // visit http://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { } // This method gets called by the runtime. Use this method to configure // the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.Run(async (context) => { await context.Response.WriteAsync(“Hello World!”); }); } } } In the Startup class, there are two methods where most of our work will take place. The Configure method of the class is where you build your HTTP processing pipeline. This defines how your application responds to requests. Currently this application can only say Hello World! and if we want the application to behave differently, we will need to change the pipeline around by adding additional code in this Configure method. For example, if we want to serve the static files such as an index.html file, we will need to add some code to the Configure method. You can also have an error page or route requests to an ASP.NET MVC controller; both of these scenarios will also require to do some work in this Configure method. In the Startup class, you will also see the ConfigureServices() method. This helps you configure components for your application. Right now, we have a hard-coded string for every response — the Hello World! string. Instead of hard-coding the string, we want to load this string from some component that knows the text that we want to display. This other component might load that text from a database or a web service or a JSON file, it doesn”t matter where exactly it is. We will just set up a scenario so that we do not have this hard-coded string. In the Solution Explorer, right-click on your project node and select Add → New Item. In the left pane, select Installed → Code and then in the middle pane, select the JSON File. Call this file AppSettings.json and click on the Add button as in the above screenshot. We can also have our program read the text from the file instead of having the Hello World! String in Startup.cs. Let us add the following code in AppSettings.json file. { “message”: “Hello, World! this message is from configuration file…” } Now we need to access this message from the Startup.cs file. Here is the implementation of the Startup.cs file which will read the above message from the JSON file. using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Configuration; namespace FirstAppDemo { public class Startup { public Startup() { var builder = new ConfigurationBuilder() .AddJsonFile(“AppSettings.json”); Configuration = builder.Build(); } public IConfiguration Configuration { get; set; } // This method gets called by the runtime. // Use this method to add services to the container. // For more information on how to configure your application, // visit http://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { } // This method gets called by the runtime. // Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app) { app.UseIISPlatformHandler(); app.Run(async (context) => { var msg = Configuration[“message”]; await context.Response.WriteAsync(msg); }); } // Entry point for the application. public static void Main(string[] args) =7gt; WebApplication.Run<Startup>(args); } } Let us now run the application. Once you run the application, it will produce the following output. Print Page Previous Next Advertisements ”;

ASP.NET Core – New Project

ASP.NET Core – New Project ”; Previous Next In this chapter, we will discuss how to create a new project in Visual Studio. Once you have installed the Visual Studio 2015 tooling, you can start building a new ASP.NET Core Application from the File → New Project menu option. On the New Project dialog box, you will see the following three different templates for Web projects − ASP.NET Web Application − The simple ASP.NET application templates . ASP.NET Core Web Application (.NET Core) − This will start you with a crossplatform compatible project that runs on the .NET Core framework. ASP.NET Core Web Application (.NET Framework) − This starts a new project that runs on the standard .NET Framework on Windows. In the left pane, select Templates → Visual C# → Web and in the middle pane select the ASP.NET Core Web Application (.NET Core) template. Let us call this application FirstAppDemo and also specify the Location for your ASP.NET Core project and then Click OK. In the above dialog box, you can select a specific template for the ASP.NET application from the available ASP.NET Core Templates. ASP.NET Core templates currently contain three different templates. Of these, the Web Application template will help you lay out a lot of files on your file system. This also allows you to use ASP.NET MVC right away. Here, we will start with an empty template. This would help us build it from scratch. Let us select the Empty template, turn off the Host in the cloud and click OK. Visual Studio will now launch the project in some time. In the Solution Explorer window, you will see all the files that are in this project. Let us run this application, you can do that by pressing Ctrl+F5 or by going to the Debug menu. After going to the Debug menu, select Start Without Debugging. This application can display only Hello World! This runs on localhost:57741. In the window system tray, you can also see that IIS Express is running. And the name of the site is FirstAppDemo. If you have been programming with ASP.NET with the previous versions of the framework, the way you would interact with the Visual Studio and the way Visual Studio uses IIS Express to host your application, all these aspects will be familiar. Print Page Previous Next Advertisements ”;

ASP.NET Core – Routing

ASP.NET Core – Routing ”; Previous Next In MVC framework, we have three components, each with its own focus on a specific part of the job. In order for all of this to work, we need to find a way to send these HTTP requests to the right controller. In ASP.NET Core MVC, this process is known as routing. Routing is the process of directing an HTTP request to a controller. Let us now understand how to route requests to different controllers. The ASP.NET Core middleware needs a way to determine if a given HTTP request should go to a controller for processing or not. The MVC middleware will make this decision based on the URL and some configuration information we provide. In this chapter, we will define this configuration information or you can say routing information inside Startup.cs when we add the MVC middleware. This approach is often referred to as the convention-based routing. The following is a code snippet for conventional routing. routeBuilder.MapRoute(“Default”, “{controller=Home}/{action=Index}/{id?}”); In this approach, we define templates that tell MVC how to look at a URL and find a controller name and an action name where a controller is a C# class and an action is a public method on that class. In the last chapter, we have created a controller (HomeController) in our application which is a C# class and doesn’t need to be derived from a base class or implement an interface or have any special attribute. It is a plain C# class with a name, HomeController and it contains the Index method which returns a string. using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace FirstAppdemo.Controllers { public class HomeController { public string Index() { return “Hello, World! this message is from Home Controller…”; } } } Here, we are going to focus on routing to controllers. We will also try understanding how routing works. Let us now return to the Startup class where we configured MVC middleware into our application. Inside the Configure method, we have used a method UseMvcWithDefaultRoute. public void Configure(IApplicationBuilder app) { app.UseIISPlatformHandler(); app.UseDeveloperExceptionPage(); app.UseRuntimeInfoPage(); app.UseFileServer(); app.UseMvcWithDefaultRoute(); app.Run(async (context) => { var msg = Configuration[“message”]; await context.Response.WriteAsync(msg); }); } This gives us a default routing rule that allows us to get to the HomeController. Instead of using the UseMvcWithDefaultRoute, let us use the UseMvc, and then configure the route at this point using a named method ConfigureRoute. The following is the implementation of the Startup.cs file. using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Configuration; using Microsoft.AspNet.Routing; using System; namespace FirstAppDemo { public class Startup { public Startup() { var builder = new ConfigurationBuilder() .AddJsonFile(“AppSettings.json”); Configuration = builder.Build(); } public IConfiguration Configuration { get; set; } // This method gets called by the runtime. // Use this method to add services to the container. // For more information on how to configure your application, // visit http://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddMvc(); } // This method gets called by the runtime. // Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app) { app.UseIISPlatformHandler(); app.UseDeveloperExceptionPage(); app.UseRuntimeInfoPage(); app.UseFileServer(); app.UseMvc(ConfigureRoute); app.Run(async (context) => { var msg = Configuration[“message”]; await context.Response.WriteAsync(msg); }); } private void ConfigureRoute(IRouteBuilder routeBuilder) { //Home/Index routeBuilder.MapRoute(“Default”, “{controller = Home}/{action = Index}/{id?}”); } // Entry point for the application. public static void Main(string[] args) => WebApplication.Run<Startup>(args); } } Inside the ConfigureRoute method, you can configure your routes; you can see that this method has to take a parameter of type IRouteBuilder. The goal of routing is to describe the rules that ASP.NET Core MVC will use to process an HTTP request and find a controller that can respond to that request. You can have one route that can map requests to different controllers. We can tell the routeBuilder that we want to map a new route and its name is “Default” and then provide the most important piece of routing information, which is the template. The template is a string, and it is going to describe to ASP.NET Core MVC how to pull apart a URL. In the last example, we have added a HomeController, so you can also request any of the following URLs, and they will be directed to the Index action on the HomeController as well. http://localhost:49940 http://localhost:49940/Home http://localhost:49940/Home/Index When a browser requests http://mysite/or http://mysite/Home, it gets back the output from the HomeController’s Index method. You can try this as well by changing the URL in the browser. In this example, it is http://localhost:49940/, except that the port which might be different. If you append /Home or /Home/Index to the URL and press the Enter button, you will see the same result. The question mark at the end of ID means that this parameter is optional. In other words, ASP.NET Core MVC doesn”t have to see some sort of ID here, which might be a number, or a string or GUID. Let us run the application in the browser. Once the application is run, you will see the following output. You can see a message pop up from the app.Run middleware, and the reason we are getting this message is because the MVC middleware saw that URL. This was a request to the root of the website, which didn”t find a controller name or an action name in the URL. The root of the website gave up processing that request and passed the request to the next piece of middleware, which is the app.Run code. The template for the route we have specified is quiet unlike the default template. In the default template, there are some default values to apply if a controller and an action name aren”t found. If a request comes in to the root of the website, the default controller name would be Home. You could change that to any other controller as you want and the default action name can be Index. You can also change the default action if you want as shown in the following program. private void ConfigureRoute(IRouteBuilder routeBuilder)

ASP.NET Core – Project.Json

ASP.NET Core – Project.Json ”; Previous Next In this chapter, we will discuss the project.json file. This file is using JavaScript object notation to store configuration information and it is this file that is really the heart of a .NET application. Without this file, you would not have an ASP.NET Core project. Here, we will discuss some of the most important features of this file. Let us double-click on the project.json file. Currently, the default code implementation in project.json file is as follows − { “dependencies”: { “Microsoft.NETCore.App”: { “version”: “1.0.0”, “type”: “platform” }, “Microsoft.AspNetCore.Diagnostics”: “1.0.0”, “Microsoft.AspNetCore.Server.IISIntegration”: “1.0.0”, “Microsoft.AspNetCore.Server.Kestrel”: “1.0.0”, “Microsoft.Extensions.Logging.Console”: “1.0.0” }, “tools”: { “Microsoft.AspNetCore.Server.IISIntegration.Tools”: “1.0.0-preview2-final” }, “frameworks”: { “netcoreapp1.0”: { “imports”: [“dotnet5.6”, “portable-net45+win8”] } }, “buildOptions”: { “emitEntryPoint”: true, “preserveCompilationContext”: true }, “runtimeOptions”: { “configProperties”: { “System.GC.Server”: true } }, “publishOptions”: { “include”: [“wwwroot”, “web.config” ] }, “scripts”: { “postpublish”: [ “dotnet publish-iis –publish-folder %publish:OutputPath% –framework %publish:FullTargetFramework%” ] } } As we see, we have version information at the top of this file. This is the version number your application will use when you build it. The version is 1.0.0, but the most important part of this file is the dependencies. If your application is going to do any useful work, then you will need libraries and frameworks to do that work, such storing and retrieving data to/from a database or render complicated HTML. With this version of ASP.NET Core, the dependencies are all managed via the NuGet package manager. NuGet has been around the .NET space for a few years, but now the primary way to manage all your dependencies is by using libraries and frameworks that are wrapped as NuGet packages. All of the top-level NuGet packages your application needs will be stored in this project.json file. “Microsoft.AspNetCore.Diagnostics”: “1.0.0”, “Microsoft.AspNetCore.Server.IISIntegration”: “1.0.0”, “Microsoft.AspNetCore.Server.Kestrel”: “1.0.0”, “Microsoft.Extensions.Logging.Console”: “1.0.0 You can see we have some dependencies in this file and the exact dependencies will probably change by the final release of ASP.NET. When you want to add a new dependency, say like the ASP.NET MVC framework, you easily type into this project.json file, and you will also get some IntelliSense help including not just the package name but also the version numbers as shown in the following screenshot. You can also use the UI by right-clicking on References in the Solution Explorer and then, select Manage NuGet packages. You can now see the currently installed packages. Those packages are the same ones that are in your project.json file and you can also go to the Browser and add other packages, including pre-released packages, let us say, the MVC framework installed into this project. If you install this package right now by using the Install button, then this package would be stored in project.json. The frameworks section is another important part of project.json, this section tells ASP.NET as to which of the .NET frameworks your application can use. “frameworks”: { “netcoreapp1.0”: { “imports”: [ “dotnet5.6”, “portable-net45+win8″ ] } }, In this case, you will see that “netcoreapp1.0” is the framework used in the project, you can also include the full .NET Framework which is installed when you install Visual Studio. It is the same .NET Framework that is included with many versions of the Windows Operating System. It is the .NET Framework that has been around for 15 years, and it includes the frameworks that do everything from web programming to desktop programming. It is a huge framework that works only on Windows. “netcoreapp1.0” is the .NET Core framework. It is a cross-platform framework and can work on various platforms, not just Windows but also OS X and Linux. This framework has fewer features than the full .NET framework, but it does have all the features that we need for ASP.NET Core web development. Print Page Previous Next Advertisements ”;

ASP.NET Core – Middleware

ASP.NET Core – Middleware ”; Previous Next In this chapter, we will understand how to set up middleware. Middleware in ASP.NET Core controls how our application responds to HTTP requests. It can also control how our application looks when there is an error, and it is a key piece in how we authenticate and authorize a user to perform specific actions. Middleware are software components that are assembled into an application pipeline to handle requests and responses. Each component chooses whether to pass the request on to the next component in the pipeline, and can perform certain actions before and after the next component is invoked in the pipeline. Request delegates are used to build the request pipeline. The request delegates handle each HTTP request. Each piece of middleware in ASP.NET Core is an object, and each piece has a very specific, focused, and limited role. Ultimately, we need many pieces of middleware for an application to behave appropriately. Let us now assume that we want to log information about every request into our application. In that case, the first piece of middleware that we might install into the application is a logging component. This logger can see everything about the incoming request, but chances are a logger is simply going to record some information and then pass along this request to the next piece of middleware. Middleware is a series of components present in this processing pipeline. The next piece of middleware that we”ve installed into the application is an authorizer. An authorizer might be looking for specific cookie or access tokens in the HTTP headers. If the authorizer finds a token, it allows the request to proceed. If not, perhaps the authorizer itself will respond to the request with an HTTP error code or redirect code to send the user to a login page. But, otherwise, the authorizer will pass the request to the next piece of middleware which is a router. A router looks at the URL and determines your next step of action. The router looks over the application for something to respond to and if the router doesn”t find anything to respond to, the router itself might return a 404 Not Found error. Example Let us now take a simple example to understand more about middleware. We set up the middleware in ASP.NET using the Configure method of our Startup class. using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Configuration; namespace FirstAppDemo { public class Startup { public Startup() { var builder = new ConfigurationBuilder() .AddJsonFile(“AppSettings.json”); Configuration = builder.Build(); } public IConfiguration Configuration { get; set; } // This method gets called by the runtime. // Use this method to add services to the container. // For more information on how to configure your application, // visit http://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { } // This method gets called by the runtime. // Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app) { app.UseIISPlatformHandler(); app.Run(async (context) => { var msg = Configuration[“message”]; await context.Response.WriteAsync(msg); }); } // Entry point for the application. public static void Main(string[] args) => WebApplication.Run<Startup>(args); } } Inside the Configure() method, we will invoke the extension methods on the IApplicationBuilder interface to add middleware. There are two pieces of middleware in a new empty project by default − IISPlatformHandler Middleware registered with app.Run IISPlatformHandler IISPlatformHandler allows us to work with Windows authentication. It will look at every incoming request and see if there is any Windows identity information associated with that request and then it calls the next piece of middleware. Middleware registered with app.Run The next piece of middleware in this case is a piece of middleware registered with app.Run. The Run method allows us to pass in another method, which we can use to process every single response. Run is not something that you will see very often, it is something that we call a terminal piece of middleware. Middleware that you register with Run will never have the opportunity to call another piece of middleware, all it does is receive a request, and then it has to produce some sort of response. You also get access to a Response object and one of the things you can do with a Response object is to write a string. If you want to register another piece of middleware after app.Run, that piece of middleware would never be called because, again, Run is a terminal piece of middleware. It will never call into the next piece of middleware. How to Add another Middleware Let us proceed with the following steps to add another middleware − Step 1 − To add another middleware, right-click on project and select Manage NuGet Packages. Step 2 − Search for Microsoft.aspnet.diagnostics that is actually ASP.NET Core middleware for exception handling, exception display pages, and diagnostics information. This particular package contains many different pieces of middleware that we can use. Step 3 − Install that package if it is not installed in your project. Step 4 − Let us now go to the Configure() method and invoke app.UseWelcomePage middleware. // This method gets called by the runtime. // Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app) { app.UseIISPlatformHandler(); app.UseWelcomePage(); app.Run(async (context) => { var msg = Configuration[“message”]; await context.Response.WriteAsync(msg); }); } Step 5 − Run your application and you will see the following welcome screen. This Welcome screen might not be as useful. Step 6 − Let us try something else that might be a little more useful. Instead of using the Welcome page, we will use the RuntimeInfoPage. // This method gets called by the runtime. // Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app) { app.UseIISPlatformHandler(); app.UseRuntimeInfoPage(); app.Run(async (context) => { var msg = Configuration[“message”]; await context.Response.WriteAsync(msg); }); } Step 7 − Save your Startup.cs page and refresh your browser and you will see the following page. This RuntimeInfoPage is a middleware that will only respond

ASP.NET Core – Environment Setup

ASP.NET Core – Environment Setup ”; Previous Next ASP.NET Core is a significant redesign of ASP.NET. This topic introduces the new concepts in ASP.NET Core and explains how they help you develop modern web apps. To use ASP.NET Core in your application, the following must be installed in your system − Microsoft Visual Studio 2015 Microsoft .NET Core 1.0.0 – VS 2015 Tooling Preview 2 Microsoft provides a free version of Visual Studio which also contains the SQL Server and it can be downloaded from www.visualstudio.com/en-us/downloads/downloadvisual-studio-vs.aspx and Microsoft .NET Core 1.0.0 – VS 2015 Tooling Preview 2 can be downloaded from https://go.microsoft.com/fwlink/?LinkId=817245.. Installation of Microsoft Visual Studio 2015 Let us now understand the steps involved in the installation of Step 1 − Once downloading is completed, run the installer. The following dialog box will be displayed. Step 2 − Click the Install button as in the above screenshot. The installation process will then start. Step 3 − Once the installation process is completed successfully, you will see the following dialog box. Step 4 − Close this dialog and restart your computer if required. Step 5 − Open the Visual studio from the Start menu. This will open the following dialog box and it will take some time for the first time (only for preparation). Step 6 − You will now see the main window of the Visual studio. Step 7 − Once the Visual Studio is installed, close the Visual Studio and launch the Microsoft .NET Core 1.0.0 – VS 2015 Tooling Preview 2. Step 8 − Check the checkbox and click Install. Step 9 − Once the installation is completed, you will see the following message. Step 10 − You are now ready to start your application using ASP.NET Core. Print Page Previous Next Advertisements ”;