Introduction
You might have used google forms or a spreadsheet where you need to log in to access the content inside the page. It allows you to access the page only if your mail is valid and verified by the owner. This is called “Authentication”. Similarly, the authentication technique is used for the websites too.
ASP.NET WebPages, also known as WebForms, is a web framework supported by ASP.NET. The WebForms application can be written in languages C# and VB.Net. The webForm pages are server controls used to render the pages, and they are reusable. They are used for user authentication. Let’s learn what authentication in webForms is and the steps we need to follow in the article.
WebForms
To create a webForm, we have to follow the steps listed below.
Step 1
Create a new project in the visual studio code and select the ASP.NET web application. Then assign a name for that application in the menu.
step 2
Select an empty web forms Template and select No Authentication in the Authentication field.

step 3
Authorize a Secure Socket Layer (SSL) for the form. SSL is a protocol that allows servers and clients to communicate securely using encryption.
Step 4
Select Properties on the right-click in solution explorer, set the project URL, and save it. The final URL should be the same as the SSL URL.

Step 5
After the SSL is enabled, run the application. This may ask us to install an IIS Express SSL certificate. Install it and run the application.
It will show us the following output:
This application has two links, Register and Login, in the upper right corner.
Step 6
The user can register or log in by clicking on the links and fill the details. The links will redirect the users to their respective pages.
Let’s learn to code the webForms now.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="FormAuth.Login" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title>WebForms</title>
</head>
<body>
<form id="form1" runat="server">
<h3> Login Page</h3>
<table>
<tr>
<td>Email:</td>
<td><asp:TextBox ID="email" runat="server" />
</td>
<td><asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="email" Display="Dynamic"
ErrorMessage="Cannot be empty." runat="server" />
</td>
</tr>
<tr>
<td>Password:</td>
<td><asp:TextBox ID="UserPass" TextMode="Password"
runat="server" />
</td>
<td><asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="UserPass"
ErrorMessage="Cannot be empty." runat="server" />
</td>
</tr>
<tr>
<td>Remember me?</td>
<td><asp:CheckBox ID="chkboxPersist" runat="server" />
</td>
</tr>
</table>
<asp:Button ID="Submit1" OnClick="Login" Text="Log In"
runat="server" />
<p><asp:Label ID="Msg" ForeColor="red" runat="server" />
</p>
</form>
</body>
</html>
We created a form in the above code with email and password fields. The fields are integrated with validators and a submit button.
using System;
namespace FormAuth {
public partial class Login: System.Web.UI.Page {
protected void Login_Click(object sender, EventArgs e) {
if(FormsAuthentication.Authenticate(UserName.Text, UserPass.Text)) {
FormsAuthentication.RedirectFromLoginPage(UserName.Text, chkboxPersist.Checked);
} else {
Msg.Text = "Invalid User Name and/or Password";
}
}
}
}
The user should be prevented from accessing the website by giving the link directly in the browser. So for that, we should provide a condition for secure authentication.
After the user logs in, the website will display the home page with the user's login status.