Friday, April 5, 2013

Asp.net Simple Login Form With Redirect and Session Management

Hello Friends,

Hope you have enjoyed our previous post.. Now we are coming up with asp.net Login including Session Management and redirect options.

We are having 2 Pages. 1) Login Page and 2) Menu Page

Default Login page will open when you open website, after suppose you try to login with userid: admin and password : admin then you can be redirect to menu or admin panel. Here we have shown another page. If you are trying to enter any other userid or password then home page will gives you error message that invalid userid or password.

Here is the snapshots of the website including downloadable code : 
Click Here to Download Complete Code of Login Page With Session Management and Redirect


Login Page

Login Page : Latest Technology Guide

 Invalid Userid Password Message


Invalid User id Password : Login Page : Latest Technology Guide


 Successful Login Menu page

Menu : Latest Technology Guide


For Downloading full code : Click Here :


Code for Login Button:

  Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        If TextBox1.Text = "admin" And TextBox2.Text = "admin" Then
            Session("login") = "Success" 'store some value into session so that we can check for this value in next page
            Response.Redirect("default2.aspx") 'redirect to menu page
        Else
            Label1.Text = "Invalid Useid or Password"
            Session.Clear() 'clear session values
            Session.Abandon()

        End If

    End Sub


Code for Page Lode in Page2 :
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("login") = "Success" Then
            'Load page without any problems.
        Else
            'redirect back to home page for login.
            Response.Redirect("default.aspx")


        End If
    End Sub

 

2 comments: