mmedi005
asked on
How do I build a class that uses Response object in ASP .NET?
I want to build a class that uses a sub routine like this......
Imports Microsoft.VisualBasic
Imports System.Web.UI
Public Class security
Protected Sub Is_User_Signed_In(ByVal u)
If u <> "" Then
'check user name........
Else
Response.Redirect("http://.....")
End If
End Sub
End Class
I want this class to be available globally to all my web pages? How do I do this? Is there another way, am I taking the wrong approach?
Imports Microsoft.VisualBasic
Imports System.Web.UI
Public Class security
Protected Sub Is_User_Signed_In(ByVal u)
If u <> "" Then
'check user name........
Else
Response.Redirect("http://.....")
End If
End Sub
End Class
I want this class to be available globally to all my web pages? How do I do this? Is there another way, am I taking the wrong approach?
ASKER
Am I importing the correct classes, and also I have to import the class with whatever webpage I'm using it for, right?
Dear mmedi005,
Yes, you can go with the way you applied now. However, you need to use call System.Web.HttpContext Response or Request object. Check this complete reference regarding mentioned:
http://msdn2.microsoft.com/en-us/library/system.web.httpcontext.aspx
eg:
If u <> "" Then
'check user name........
Else
System.Web.HttpContext.Cur rent.Respo nse.Redire ct("http://....." )
End If
Yes, you can go with the way you applied now. However, you need to use call System.Web.HttpContext Response or Request object. Check this complete reference regarding mentioned:
http://msdn2.microsoft.com/en-us/library/system.web.httpcontext.aspx
eg:
If u <> "" Then
'check user name........
Else
System.Web.HttpContext.Cur
End If
In the begining of your webpage (*.vb) you make the import like
Imports MyClass
Then you can use the functions that you have.
You can also do MyClass.MyFuncion bla bla bla
Imports MyClass
Then you can use the functions that you have.
You can also do MyClass.MyFuncion bla bla bla
ASKER
I have placed it inside the App_Code but VS does not like what it sees. In the code you gave me it has
Sub Is_User_Signed_In(ByVal u) - underlined in blue
If - same u <> "" Then
Else - same
Response - same .Redirect("http://.....")
End If - same
End Sub - same
all underlined in blue...why?
Sub Is_User_Signed_In(ByVal u) - underlined in blue
If - same u <> "" Then
Else - same
Response - same .Redirect("http://.....")
End If - same
End Sub - same
all underlined in blue...why?
What is U ? Its a string ?
Does you have this sub inside a class
Public Class MyClass
Public Share Sub Is_User_Signed_In(ByVal u As String)
If u <> "" Then
'check user name........
Else
Response.Redirect("http://.....")
End If
End Sub
End Sub
End Class
Does you have this sub inside a class
Public Class MyClass
Public Share Sub Is_User_Signed_In(ByVal u As String)
If u <> "" Then
'check user name........
Else
Response.Redirect("http://.....")
End If
End Sub
End Sub
End Class
ASKER
yes with this on top
Imports Microsoft.VisualBasic
Imports System.Web.UI
Dont know if im importing the correct class
also you have End Sub twice in the bottom, I only have it once...
Imports Microsoft.VisualBasic
Imports System.Web.UI
Dont know if im importing the correct class
also you have End Sub twice in the bottom, I only have it once...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Error 1 End of statement expected.
Error 2 Statement cannot appear outside of a method body.
Error 3 Statement cannot appear outside of a method body.
Error 4 Declaration expected.
Error 5 'End If' must be preceded by a matching 'If'.
Error 6 'End Sub' must be preceded by a matching 'Sub'.
Error 7 Name 'Is_User_Logged_In' is not declared
Error 2 Statement cannot appear outside of a method body.
Error 3 Statement cannot appear outside of a method body.
Error 4 Declaration expected.
Error 5 'End If' must be preceded by a matching 'If'.
Error 6 'End Sub' must be preceded by a matching 'Sub'.
Error 7 Name 'Is_User_Logged_In' is not declared
ASKER
Nice, ok, got it down to
Error 1 Name 'Response' is not declared.
Error 2 Name 'Is_User_Logged_In' is not declared.
thanks in advance, your helping me a lot and really appreciate it.... : )
Error 1 Name 'Response' is not declared.
Error 2 Name 'Is_User_Logged_In' is not declared.
thanks in advance, your helping me a lot and really appreciate it.... : )
Replace 'Response' with System.Web.HttpContext.Cur rent.Respo nse.Redire ct("http://....." ).
X_com have already post it before
X_com have already post it before
ASKER
you the man, thx jpaulino.....
Does that go for all com objects, are they all placed in that class?
thanks again... : )
Does that go for all com objects, are they all placed in that class?
thanks again... : )
Yes.
Public Share Sub Is_User_Signed_In(ByVal u)
If u <> "" Then
'check user name........
Else
Response.Redirect("http://.....")
End If
End Sub
End Class