登录后default.aspx页面无法打开.
问题描述:
Imports System.Data.SqlClient.SqlConnection
Imports System.Data.SqlClient
Public Class login11
Inherits System.Web.UI.Page
Public Function Validate_Login(ByVal Username As String, ByVal Password As String) As Integer
Dim con As SqlConnection = New SqlConnection("Data Source=KARANDE\sqlexpress;Initial Catalog=nitink;Integrated Security=True")
Dim cmdselect As SqlCommand = New SqlCommand()
cmdselect.CommandType = CommandType.StoredProcedure
cmdselect.CommandText = "[dbo].[Log_prcLog]"
cmdselect.Parameters.AddWithValue("@Username", Username)
cmdselect.Parameters.AddWithValue("@UPassword", Password)
cmdselect.Parameters.AddWithValue("@OutRes", SqlDbType.Int)
' cmdselect.Parameters.Add("@Username", SqlDbType.VarChar, 50).Value = Username
' cmdselect.Parameters.Add("@UPassword", SqlDbType.VarChar, 50).Value = Password
'cmdselect.Parameters.Add("@OutRes", SqlDbType.Int, 4)
cmdselect.Parameters("@OutRes").Direction = ParameterDirection.Output
cmdselect.Connection = con
Dim Results As Integer = 0
Try
con.Open()
cmdselect.ExecuteNonQuery()
Results = CType(cmdselect.Parameters("@OutRes").Value, Integer)
Catch ex As SqlException
lblMessage.Text = ex.Message
Finally
cmdselect.Dispose()
If Not con Is Nothing Then
con.Close()
End If
End Try
Return Results
End Function
Protected Sub btnlogin_Click(sender As Object, e As EventArgs)
Dim Results As Integer = 0
If txtUsername.Text <> String.Empty AndAlso txtPassword.Text <> String.Empty Then
Results = Validate_Login(txtUsername.Text.Trim(), txtPassword.Text.Trim())
If Results = 1 Then
lblMessage.Text = "Login is Good, Send the User to another page or enable controls"
Else
lblMessage.Text = "Invalid Login"
lblMessage.ForeColor = System.Drawing.Color.Red
End If
Else
lblMessage.Text = "Please make sure that the username and the password is Correct"
End If
End Sub
End Class
答
If Results = 1 Then
lblMessage.Text = "Login is Good, Send the User to another page or enable controls"
Else
lblMessage.Text = "Invalid Login"
lblMessage.ForeColor = System.Drawing.Color.Red
End If
Else
lblMessage.Text = "Please make sure that the username and the password is Correct"
End If
您只在标签中显示消息.重定向代码在哪里(default.aspx),并检查Results变量上的值.
Your are showing only message in the label. Where is the redirection code.(default.aspx ) and check what value you are getting on Results variable.