andycharger
Well-known member
- Joined
- Apr 2, 2003
- Messages
- 152
Can someone explain to me where and how I declare the FormsAuthentication method?
I am building a login page and I want to use the FormsAuthentication when im verified and return my user to the right page.
I have included my code. Im getting blue squiggles under the word FormsAuthentication at rthe moment!
I am building a login page and I want to use the FormsAuthentication when im verified and return my user to the right page.
I have included my code. Im getting blue squiggles under the word FormsAuthentication at rthe moment!
Code:
Public Class logon
Inherits System.Web.UI.Page
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents Label3 As System.Web.UI.WebControls.Label
Protected WithEvents LinkButton3 As System.Web.UI.WebControls.LinkButton
Protected WithEvents LinkButton4 As System.Web.UI.WebControls.LinkButton
Protected WithEvents LinkButton5 As System.Web.UI.WebControls.LinkButton
Protected WithEvents LinkButton6 As System.Web.UI.WebControls.LinkButton
Protected WithEvents LinkButton7 As System.Web.UI.WebControls.LinkButton
Protected WithEvents HyperLink1 As System.Web.UI.WebControls.HyperLink
Protected WithEvents HyperLink2 As System.Web.UI.WebControls.HyperLink
Protected WithEvents RequiredFieldValidator1 As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents RequiredFieldValidator2 As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents Submit1 As System.Web.UI.HtmlControls.HtmlInputButton
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
#Region " Web Form Designer Generated Code "
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
CODEGEN: This method call is required by the Web Form Designer
Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
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
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strSql As String
Dim strUsername As String
Dim strPW As String
Dim cnSQL As String
cnSQL = "Server=localhost;DataBase=megabytes; integrated Security=SSPI"
strUsername = TextBox1.Text
strPW = TextBox2.Text
If strUsername = "" Then
Response.Write("You did not enter a username")
Else
If strPW = "" Then
Response.Write("You did not enter a password")
Else
strSql = "Select * from Users where username = " & strUsername & " and password=" & strPW & ""
CreateMySqlDataReader(strSql, cnSQL)
End If
End If
End Sub
Public Sub CreateMySqlDataReader(ByVal mySelectQuery As String, _
ByVal myConnectionString As String)
Dim myConnection As New SqlConnection(myConnectionString)
Dim myCommand As New SqlCommand(mySelectQuery, myConnection)
myCommand.Connection.Open()
Dim strName As String
Dim myReader As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
If myReader.Read() Then
Dim ckCookie As HttpCookie = Request.Cookies("UserId")
If ckCookie Is Nothing Then
Response.Cookies("userId").Value = myReader("UserID")
Else
End If
Response.Redirect("WebForm1.aspx")
FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, PersistCookie.Checked)
Console.WriteLine(myReader.GetString(0))
Else
Response.Write("Either your username or password were inccorect.")
End If
myReader.Close()
myConnection.Close()
End Sub
End Class