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?
mmedi005Asked:
Who is Participating?
 
Jorge PaulinoConnect With a Mentor IT Pro/DeveloperCommented:
Sorry wrong typing

Public Shared Sub Is_User_Signed_In(ByVal u As String)
       If u <> "" Then
                 'check user name........
        Else
            Response.Redirect("http://.....")
        End If
End Sub
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
You must place your class inside the App_Code and change to:

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
0
 
mmedi005Author Commented:
Am I importing the correct classes,  and also I have to import the class with whatever webpage I'm using it for, right?
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
David H.H.LeeCommented:
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.Current.Response.Redirect("http://.....")
        End If
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
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
0
 
mmedi005Author Commented:
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?
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
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

0
 
mmedi005Author Commented:
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...
0
 
mmedi005Author Commented:
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
0
 
mmedi005Author Commented:
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....  :  )
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
Replace 'Response' with System.Web.HttpContext.Current.Response.Redirect("http://.....").

X_com have already post it before
0
 
mmedi005Author Commented:
you the man, thx jpaulino.....

Does that go for all com objects, are they all placed in that class?

thanks again...  :  )
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
Yes.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.