Hello Friends, in this tutorial I am going to create a simple Login Form in ASP.NET MVC. I am not using database or Authorization and Authonthentication for performing this task.
After completing this tutorial you will be able to:
- Create a simple Login Form in ASP.NET MVC.
Introduction:
Login Module is very important for any project. In this tutorial, I am going to create a simple Login Form without any Database.
Simple Login Form in ASP.NET MVC.
Follow the steps to create a Login Form in ASP.NET MVC.
Step 1 – Start Visual Studio and create an ASP.NET MVC application with the name LoginFormDemo.
Step 2- Choose an Empty template and Click OK.
Your solution will look like this.
Step 3- Right Click on Controller folder and add a Controller with the name Home.
Your HomeController will look like this.
Step 4- Now it’s time to create User Interface i.e, View. Right Click on the Index Action method and add Click on “Add View”.
Click on Add button.
Step 5- Now we need to add Model for this Right click on the Model folder in Solution Explorer and add a class. Model is simple a C# class and nothing else.
Step 6- Type a name UserLoginModel and Click on Add button.
Step 7- Write following code in UserLoginModel.
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace LoginFormDemo.Models { public class UserLoginModel { public string UserName { get; set; } public string Password { get; set; } public string Message { get; set; } } }
Step 8- Now go to Index View and write following code.
@model LoginFormDemo.Models.UserLogin @{ ViewBag.Title = "Index"; } <h2>Index</h2> @using (Html.BeginForm()) { @Html.AntiForgeryToken() @Html.ValidationSummary(true) if (Model != null) { <h1> @Model.Message </h1> } <fieldset> <legend>UserLogin</legend> <div class="editor-label"> @Html.LabelFor(model => model.UserName) </div> <div class="editor-field"> @Html.TextBoxFor(model => model.UserName) @Html.ValidationMessageFor(model => model.UserName) </div> <div class="editor-label"> @Html.LabelFor(model => model.Password) </div> <div class="editor-field"> @Html.PasswordFor(model => model.Password) @Html.ValidationMessageFor(model => model.Password) </div> <p> <input type="submit" value="Login" /> </p> </fieldset> }
Step 8- Now go to HomeController and add following code.
[HttpPost] public ActionResult Index(UserLoginModel objUserLogin) { if (objUserLogin.UserName == "debugonweb" && objUserLogin.Password == "debugonweb") return RedirectToAction("WelcomePage"); else { objUserLogin.Message = "Invalid UserName/Password"; return View(objUserLogin); } }
In above code, you can see we verified the User Name and Password after this the user will be redirected to Welcome Page. This line of code is responsible for redirecting the user to the Welcome page.
return RedirectToAction("WelcomePage");
In the case of wrong User Name and Password, an error will be thrown.
Step 9- Now what we need to do is to create a Welcome Page for User. For this first add an Action method in HomeController.
public ActionResult WelcomePage() { return View(); }
Step 10- Now associate this Action method with a View. Right Click on WelcomePage action method and add a View with the name WelcomePage. Write following code in WelcomePage.cshtml file.
@{ ViewBag.Title = “WelcomePage”; } <h2>Welcome To Debug On Web Login Form Demo</h2>
So all done now we need to test the application. Run the application.
Now enter debugonweb in User Name textbox and debugonweb in password textbox and click on Login button. A welcome page will appear.
You can download the complete source code from here.
You must also follow the related links.
- CRUD Operation using NHibernate in ASP.NET MVC.
- Web Grid in ASP.NET MVC.
- Introduction to Entity Framework in .NET.
- Signalr in ASP.NET MVC.
Hope this post is helpful for you. We will continue writing on useful topics in the upcoming tutorials.
Thank You.
1000 loans
cost of tamoxifen tablets
sildenafil buy without prescription
200 mg viagra online
hydroxychloroquine 40 mg
buy plaquenil online uk
generic tadalafil us
tadalafil 100mg tablets
where can you buy cialis cheap
20 mg sildenafil cheap
levitra tablet buy online
reliable online pharmacy
best viagra for sale
generic cialis prices
urispas price
viagra .com
ivermectin 6 mg tablets
can i order viagra online
bad credit loan online
buy sildenafil 50mg uk
buying viagra without prescription
online personal loans
buy cialis online in canada
online tadalafil 20mg
dexamethasone online
http://bambulapharmacy.com
usa pharmacy online viagra
tadalafil 10mg online india
dexona drug
how to get female viagra
cipla cialis
cialis pills uk
where can i buy generic viagra
cardura tablets 2mg
plaquenil 25 mg
canadian viagra pharmacy
tadalafil online purchase
where to get viagra without prescription
best place to buy nolvadex
hydroxychloroquine 90mg
https://vardenafilz.com
hyzaar 100 12.5 mg
buy viagra tablet online india
viagra pharmacy usa
online pharmacy group
generic for viagra 100mg
online payday loans
buy viagra tablet india online
buy synthroid 175 mcg
purchase tadalafil 5mg online
buy chloroquine online
plaquenil 200 mg 60 tab
amoxicillin 500 mg
prednisolone without prescription
tretinoin 025 cost
aralen buy
amoxicillin clavulanate
cialis in mexico over the counter
viagra pills over the counter
buy cialis 2.5 mg online
best payday loan lender
price of amoxicillin without insurance
buy cialis daily use online
stromectol for sale
india pharmacy online tadalafil
amoxicillin 600mg
online tadalafil canada
azithromycin 250 mg buy online
Thanks. An abundance of tips. rn order viagra with paypal
direct lender payday
levitra uk prescription
generic cialis for sale online
order viagra online canadian pharmacy
over the counter prednisone medicine
loans in maryland
http://sansordonnancefr.com – cialis sans ordonnance
order viagra mexico
hydroxychloroquine order online
generic zithromax online paypal
propecia costs australia
amoxicillin 1500 mg daily
doxycycline 40 mg coupon
lyrica 75 mg coupon
canadian purchase propecia
hydroxychloroquine sulfate tablet
cheap viagra 100 online
tadalafil canadian pharmacy online
sterapred ds
best price for synthroid 50 mcg
promo code for canadian pharmacy meds
the loan
average cost viagra
ny state of health viagra without a doctor prescription
chloroquine over the counter
zithromax canadian pharmacy
zithromax z-pak
2600 installment loans in california
cheap generic cialis india
tadalafil daily use
how much does aralen cost
canadian pharmacy no prescription cialis
where can i buy clomid pills online
how much is chloroquine
doxycycline brand
medicine azithromycin 250 mg
where can i buy real clomid online
http://withoutscript.com – price difference between viagra cialis
levitra from canada
cash advance payday loan
how do loans work
best female viagra pills in india
buy synthroid online from canada
zithromax drug
plaquenil uk price
otc prednisone cream
cheapest 20 mg cialis
buy prednisone online from canada
clomid canada pharmacy
aralen tab
medical pharmacy south
canadian pharmacy world