How to create an ASP.Net Core Web Application
Open Visual Studio 2017. Go to File menu, point to new and click new project. New Project Window will open, you can select an installed template like “.NET Core” in Visual C# Template and then select the Asp.Net Core Web Application (.NET Core) and type Project Name AspNetCoreHelloWorldApp. Choose the project location path and click OK button.
The New Asp.NET Core Web Application (.NET Core) - AspNetCoreHelloWorldApp window will open and Select an Asp.Net Core version 1.1 in the Dropdown box. Select a template as Web Application and keep the default No Authentication. Then, Click OK button.
Now, you can see AspNetCoreHelloWorldApp project structure, as shown in the screenshot, given below
Now, we can run the app with/ without debug mode. If you want to run the app in debug mode.
Pressing the F5 button to run the app in debug mode. Otherwise, you can go to debug menu item in Visual Studio. Then, click the Start Debugging sub menu item.
Now, successfully launched the app in the browser
If you want to run the app in non-debug mode. Pressing Ctrl+F5 button to run the app in non-debug mode. Otherwise, you can go to debug menu item in Visual Studio. Then, click the Start Without Debugging sub menu item.
Now, successfully launched the app in the browser
How to add new Controller
In Solution Explorer, Go to the Controllers folder, right-click the Controllers folder and point to Add, followed by clicking the New Item.
You can select an MVC Controller class and type the class name as HelloWorldController and click the Add button.
Copy and past the below code into HelloWorldController.cs
using Microsoft.AspNetCore.Mvc;
// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace AspNetCoreHelloWorldApp.Controllers
{
public class HelloWorldController : Controller
{
// GET: /<controller>/
public IActionResult Index()
{
ViewBag.Title = "Index";
ViewBag.Message = "Hello World";
return View();
}
}
}
Now, you can change the controller name as shown in the below screenshot
How to add new View
In Solution Explorer, Go to the Views folder, right-click the views folder and point to Add, followed by clicking the New Folder. Then, the name of the folder HelloWorld.
In Views folder, Go to the HelloWorld folder, right-click the HelloWorld folder and point to Add, followed by clicking the New Item.
You can select an MVC View page and type file name as Index and click Add button.
Copy and paste the below code into Views/HelloWorld/Index.cshtml
@*
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
ViewData["Title"] = @ViewBag.Title;
}
<h2>@ViewBag.Title</h2>
<p>@ViewBag.Message</p>
How to run the HelloWorld App
Pressing the F5 or CTRL + F5 button to run the app in debug mode or non-debug mode as shown in the below screenshot
Conclusion
I hope you understood how to create a HelloWorld App using Asp.Net Core 1.1 and Visual Studio 2017, How to add new Controller, How to add the new view and How to run the HellowWorld App. I have covered all the required things. If you found anything which I missed in this article, Please let me know. Please share your valuable feedback or comments and suggestion to improve the future articles.