J
Joe Rigley
Hi,
I have a custom class with a public method. I want to perform a
repose.redirect if an error occurs in the public method GetUserRoles.
Unfortunately, Visual Studio 2003 is throwing an error when I try to do
this.
I have imported the System.Web namespace and the same code works fine on a
..aspx page. Can you not perform response.redirects in a custom class that
is being called by another aspx page? Please help.
The error I get is: "Name 'Response' is not declared" and it points to the
response.redirect line of code.
Can anyone shed some light on this?
Here's the code from the custom class:
Option Strict On
Imports System
Imports System.Collections
Imports System.Data
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.Security
Imports System.Web.UI
Imports System.Data.SqlClient
Namespace RoleSecurity
'Public Class UserHelpers
' A static string that contains the path to the XML users file
Public Shared strDbConn As String =
"Server=10.144.125.2;uid=web_user;pwd=xxx;database=Pubs"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Returns an Array of user roles for a given username
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Shared Function GetUserRoles(ByVal username As String) As String()
' Create a string to persist the roles
Dim roleStr() As String
Dim userRoles As New ArrayList
Dim conDB As SqlConnection
Dim cmdSelectRoles As SqlCommand
Dim dtrRoles As SqlDataReader
'Create db conn object
conDB = New SqlConnection(strDbConn)
Try
'open db connection
conDB.Open()
cmdSelectRoles = New SqlCommand("SELECT UPPER([Role_Code_Txt]) as RoleCode
FROM([SpartanMotors].[dbo].[Master_Users_Roles_X_Ref_Tbl]) " & _
"WHERE (LOWER(User_ID_Txt) = LOWER('rigs')) AND ( (InActiveOn_Date IS NULL)
OR (GETDATE() < InActiveOn_Date) ) ", conDB)
dtrRoles = cmdSelectRoles.ExecuteReader()
While dtrRoles.Read()
userRoles.Add(dtrRoles("RoleCode"))
End While
dtrRoles.Close()
conDB.Close()
Catch ex As Exception
'**************************************************************************
'Error occurs on line below
Response.Redirect("Login.aspx?e=1")
'*************************************************************************
End Try
roleStr = CType(userRoles.ToArray(GetType(String)), String())
Return roleStr
End Function ' GetUserRoles
End Class
End Namespace
I have a custom class with a public method. I want to perform a
repose.redirect if an error occurs in the public method GetUserRoles.
Unfortunately, Visual Studio 2003 is throwing an error when I try to do
this.
I have imported the System.Web namespace and the same code works fine on a
..aspx page. Can you not perform response.redirects in a custom class that
is being called by another aspx page? Please help.
The error I get is: "Name 'Response' is not declared" and it points to the
response.redirect line of code.
Can anyone shed some light on this?
Here's the code from the custom class:
Option Strict On
Imports System
Imports System.Collections
Imports System.Data
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.Security
Imports System.Web.UI
Imports System.Data.SqlClient
Namespace RoleSecurity
'Public Class UserHelpers
' A static string that contains the path to the XML users file
Public Shared strDbConn As String =
"Server=10.144.125.2;uid=web_user;pwd=xxx;database=Pubs"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Returns an Array of user roles for a given username
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Shared Function GetUserRoles(ByVal username As String) As String()
' Create a string to persist the roles
Dim roleStr() As String
Dim userRoles As New ArrayList
Dim conDB As SqlConnection
Dim cmdSelectRoles As SqlCommand
Dim dtrRoles As SqlDataReader
'Create db conn object
conDB = New SqlConnection(strDbConn)
Try
'open db connection
conDB.Open()
cmdSelectRoles = New SqlCommand("SELECT UPPER([Role_Code_Txt]) as RoleCode
FROM([SpartanMotors].[dbo].[Master_Users_Roles_X_Ref_Tbl]) " & _
"WHERE (LOWER(User_ID_Txt) = LOWER('rigs')) AND ( (InActiveOn_Date IS NULL)
OR (GETDATE() < InActiveOn_Date) ) ", conDB)
dtrRoles = cmdSelectRoles.ExecuteReader()
While dtrRoles.Read()
userRoles.Add(dtrRoles("RoleCode"))
End While
dtrRoles.Close()
conDB.Close()
Catch ex As Exception
'**************************************************************************
'Error occurs on line below
Response.Redirect("Login.aspx?e=1")
'*************************************************************************
End Try
roleStr = CType(userRoles.ToArray(GetType(String)), String())
Return roleStr
End Function ' GetUserRoles
End Class
End Namespace