dear all
After Login I would like to show Username into all pages, I have done the following code. what extra peace of coding required, please help
Step 1 Login Page : ------------------- Imports System.Data Imports System.Data.SqlClient
Dim con As New SqlConnection Dim cmd As New SqlCommand Dim dr As SqlDataReader Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load con.ConnectionString = ConfigurationSettings.AppSettings("ConnectionString") End Sub
Private Sub submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles submit.Click Try con.Open() cmd = New SqlCommand("Select username,userpass from test where username='" & Me.txtusername.Text & "' and userpass='" & Me.txtpwd.Text & "'", con) dr = cmd.ExecuteReader If dr.Read Then Session("username") = Me.txtusername.Text.ToUpper() Response.Redirect("testPage.aspx", False) Else Me.lblmsg.Visible = True Me.lblmsg.Text = "Wrong Entry" End If Catch ex As Exception Me.lblmsg.Visible = True Me.lblmsg.Text = ex.ToString Finally con.Close() End Try End Sub
Step 2 TestPage : Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here If Session("username") Is Nothing Then Response.Redirect("Login.aspx") End If End Sub
|
| Author: badamsreekar 31 Jul 2007 | Member Level: Silver | Rating: Points: 2 |
if ur using forms authentication... then in user control of ur application place a label and write Label1.Text = "WELCOME...." + Context.User.Identity.Name;
|
| Author: Meena Mehra 31 Jul 2007 | Member Level: Gold | Rating: Points: 2 |
in ur login page just on page_load event write the code session.add("login name")=txtloginname.text and then u can use this session login name to the next open page but do remember that u should always add this code in every page otherwise it will clear the session ok i hope u understand. one thing more use the autopostback function otherwise it will print the login name as no of times the page will refresed bye
|