nikhiljain27
Member
- Joined
- Nov 11, 2005
- Messages
- 14
- Programming Experience
- 1-3
I m implementing forms authentication on my web form. In this case i enter the url the site execute and login page is the first page that display for all the pages. But i need that few pages should be accessible by anyone and prior login to "account.aspx" and few other pages should be redirect to "login.aspx".
i have done this in "web.config":--
<authentication mode="Forms">
<forms loginUrl="login.aspx"></forms>
</authentication>
<authorization>
<deny users="?" />
Code in "Login .aspx" :-->
Imports System.Web.Security
Private Sub bttnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnok.Click
'Dim tempcon As String = ConfigurationSettings.AppSettings("salescon")
Try
Dim dr As SqlClient.SqlDataReader
con.ConnectionString = "server=192.168.11.62;integrated security=true; database=sales"
con.Open()
comm.Connection = con
comm.CommandType = CommandType.StoredProcedure
comm.CommandText = "spsaleslogin"
comm.Parameters.Add("@salesuid", txtUserName.Text)
comm.Parameters.Add("@salespwd", txtPassword.Text)
dr = comm.ExecuteReader
If dr.Read Then
If ((txtUserName.Text = dr.GetValue(1)) And (txtPassword.Text = dr.GetValue(2))) Then
FormsAuthentication.RedirectFromLoginPage(txtPassw ord.Text, False)
If FormsAuthentication.Authenticate(dr.GetValue(1), dr.GetValue(2)) = True Then
Response.Redirect("account.aspx")
Else
Response.Redirect("aboutus.aspx")
End If
End If
Else
Response.Write("Please Enter Correct UserId And Password")
End If
Catch e1 As Exception
txtUserName.Text = e1.Message
Finally
con.Close()
End Try
End Sub
i have done this in "web.config":--
<authentication mode="Forms">
<forms loginUrl="login.aspx"></forms>
</authentication>
<authorization>
<deny users="?" />
Code in "Login .aspx" :-->
Imports System.Web.Security
Private Sub bttnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnok.Click
'Dim tempcon As String = ConfigurationSettings.AppSettings("salescon")
Try
Dim dr As SqlClient.SqlDataReader
con.ConnectionString = "server=192.168.11.62;integrated security=true; database=sales"
con.Open()
comm.Connection = con
comm.CommandType = CommandType.StoredProcedure
comm.CommandText = "spsaleslogin"
comm.Parameters.Add("@salesuid", txtUserName.Text)
comm.Parameters.Add("@salespwd", txtPassword.Text)
dr = comm.ExecuteReader
If dr.Read Then
If ((txtUserName.Text = dr.GetValue(1)) And (txtPassword.Text = dr.GetValue(2))) Then
FormsAuthentication.RedirectFromLoginPage(txtPassw ord.Text, False)
If FormsAuthentication.Authenticate(dr.GetValue(1), dr.GetValue(2)) = True Then
Response.Redirect("account.aspx")
Else
Response.Redirect("aboutus.aspx")
End If
End If
Else
Response.Write("Please Enter Correct UserId And Password")
End If
Catch e1 As Exception
txtUserName.Text = e1.Message
Finally
con.Close()
End Try
End Sub