How to Call a function from a class in Visual Studio Solution
Now to working with Visual Studio Solutions, but I am trying something very basic but no joy.
So in my project I have a folder App_Code and in this I added a class called Test.vb
and added a simple function
Public Class Test2
Public Function ReplaceXSS(ByVal InputString As String) As String
InputString = InputString.Replace("<script>", "")
InputString = HttpUtility.HtmlEncode(InputString)
InputString = InputString.Replace("</script>", "")
InputString = InputString.Replace("&开发者_如何学Python", "&")
InputString = InputString.Replace("<", "<")
InputString = InputString.Replace(">", ">")
InputString = InputString.Replace("%", "%")
InputString = InputString.Replace("|", "|")
InputString = InputString.Replace("$", "$")
InputString = InputString.Replace("'", "'")
InputString = InputString.Replace("""", "\")
ReplaceXSS = InputString
End Function
End Class
But in my Default.aspx page I am struggling to find the correct syntax to call this method.
Also it doesnt seem like my Test2.vb class is correctly included in the project because If I make a type the project still builds successfully when it shouldnt
The problem is that you Test2 is under some namespace, that's you are unable to make object of that class. You have to mention the namespace before class name Dim test As New NameSpace.Test2
Dim test As New Test2 ' Make an object of that class
test.ReplaceXSS(Parameters.....) ' access the method
You need to make sure you have a reference to the project that houses Test2
. After you have a reference, you should be able to:
Dim MyTest2 As New Test2
If you still cannot instantiate an instance of the object, make sure there is no namespace you defined. If there is, prefix Test2 with the name of the namespace plus a dot.
精彩评论