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

 

3 comments:

  1. Harrah's Resort Southern California - Mapyro
    Harrah's Resort 평택 출장샵 Southern 거제 출장마사지 California. 777 Harrah's Rincon 문경 출장샵 Way, 92082 김포 출장샵 760-751-3100. (760) 851-7711. 안성 출장안마 Map. 777 Harrah's Rincon Way, 92082.

    ReplyDelete