How To Make Login Page In Visual Studio 2017

How To Articles

In this article, I will guide you through the process of creating a login page in Visual Studio 2017. As a developer, I understand the importance of a secure login page for any application. So, let’s get started!

Setting Up the Project

To create a login page in Visual Studio 2017, we first need to set up a new project. Open Visual Studio 2017 and click on “File” in the toolbar. From the dropdown menu, select “New” and then “Project”.

Choose the appropriate project template for your application, such as “ASP.NET Web Application” if you’re building a web application. Give your project a meaningful name and click “OK” to create the project.

Designing the Login Page

Once the project is created, you will be redirected to the Visual Studio IDE. In the Solution Explorer, locate the “Views” folder and expand it. Right-click on the “Home” folder and select “Add” -> “View”.

Give your login page a name, such as “Login.cshtml”, and choose the appropriate template for your needs. For simplicity, we will use the default template. Click “Add” to create the login page.

Now, open the “Login.cshtml” file. Here, you can design your login page using HTML, CSS, and JavaScript. Add a form for users to enter their credentials and a submit button to log in. You can also include additional elements like a logo or a background image to personalize your login page.

Adding Functionality to the Login Page

Once the design of the login page is complete, we need to add the necessary functionality. In the “Login.cshtml” file, locate the form element and add the following code:

@using (Html.BeginForm("Login", "Account", FormMethod.Post))
// Input fields for username and password

@Html.LabelFor(model => model.Username)
@Html.TextBoxFor(model => model.Username, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Username)
@Html.LabelFor(model => model.Password)
@Html.PasswordFor(model => model.Password, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Password)

// Submit button


This code creates a form that sends the user’s login credentials to the “Login” action in the “Account” controller when the submit button is clicked. The controller will handle the authentication process and redirect the user to the appropriate page based on the login result.

Adding Authentication and Authorization

To implement authentication and authorization in your login page, you need to configure the necessary settings in your project. Open the “Startup.cs” file and locate the “ConfigureServices” method. Add the following code:

.AddCookie("LoginCookie", options =>
options.Cookie.Name = "LoginCookie";
options.LoginPath = "/Account/Login";
options.AccessDeniedPath = "/Account/AccessDenied";

This code configures the authentication middleware to use a cookie-based authentication scheme named “LoginCookie”. It also specifies the login and access denied paths for redirecting the user accordingly.


In this article, we have covered the process of creating a login page in Visual Studio 2017. Starting from setting up the project to designing the login page and adding authentication and authorization, we have explored the necessary steps to create a secure login page for your application.

Remember, a well-designed and secure login page is essential for protecting user data and ensuring a smooth user experience. By following the steps outlined in this article, you can confidently create a login page that meets your application’s needs.

For more detailed information and code samples, you can check out the official documentation of Visual Studio 2017 and ASP.NET. Happy coding!