Controlling site from Master Page?
I have a web app that contains 1 master page and a bunch of content pages. One of the content pages is "SysLogin.aspx", which is called from a menu option from the Master Page. When the page is called, the user logs in. However, there is a "Login" button. In the code behind of the Login_Click() event, the the user successfully logs in, they are supposed to be redirected to a "Default.aspx" page and the Main Menu is enabled. Problem is, the app hangs on the redirect statement and it goes to the Catch portion of the Try Catch construct. For some reason, when I examine the exception, it only says "Unable to evaluate expression". Below is my code. My question, other than what I've stated is...should your application be controlled using code in the Master Page or in child pages. My code from the "SysLogin.aspx" is below. It hangs on the highlighted line of code.
Code:
Private Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Try
If txtLoginID.Text.Length > 0 Then
If txtPassword.Text.Length > 0 Then
If dbIO.ValidateUser(txtLoginID.Text, txtPassword.Text) Then
Session("LoggedIn") = txtLoginID.Text
Session("loggedInOk") = "Y"
Response.Redirect("~/Admin/Default.aspx")
End If
End If
End If
Catch ex As Exception
Master.errMsg = dbIO.DisplayError("btnLogin_Click()", "SysLogin", ex.Message)
End Try
End Sub
Re: Controlling site from Master Page?
Hello,
Are you getting a ThreadAbortedException?
If so, check out the documentation here:
http://msdn.microsoft.com/en-us/libr...(v=vs.80).aspx
Calling Redirect raises this exception, but you can use the second parameter to Response.Redirect to "handle" this.
Gary
Re: Controlling site from Master Page?
Gary,
I remember seeing an error message similar to what you mentioned. However, I looked at the link you provided and placed the exact code in my page. Now I'm getting an "Object reference not set to an instance of an object" error on the highlighted line of code. Here's my code now!
Code:
Private Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Try
If txtLoginID.Text.Length > 0 Then
If txtPassword.Text.Length > 0 Then
If dbIO.ValidateUser(txtLoginID.Text, txtPassword.Text) Then
If Response.IsClientConnected Then
Session("LoggedIn") = txtLoginID.Text
Session("loggedInOk") = "Y"
Dim instance As HttpResponse
Dim url As String = "~/Admin/Default.asxp"
Dim endResponse As Boolean
instance.Redirect(url, endResponse)
Else
Response.End()
End If
End If
End If
End If
Catch ex As Exception
Master.errMsg = dbIO.DisplayError("btnLogin_Click()", "SysLogin", ex.Message)
End Try
End Sub
Re: Controlling site from Master Page?
Hello,
That particular code is just dummy code, none of the variables have been instantiated, look further down the page for actual example.
Gary