• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

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?
0
mmedi005
Asked:
mmedi005
  • 6
  • 6
1 Solution
 
jpaulinoCommented:
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
 
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
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 
jpaulinoCommented:
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
 
jpaulinoCommented:
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
 
jpaulinoCommented:
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
 
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
 
jpaulinoCommented:
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
 
jpaulinoCommented:
Yes.
0

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now