开发者

How to Call a function from a class in Visual Studio Solution

开发者 https://www.devze.com 2023-03-21 04:17 出处:网络
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

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", "&#38;")
    InputString = InputString.Replace("<", "&#60;")
    InputString = InputString.Replace(">", "&#62;")
    InputString = InputString.Replace("%", "&#37;")
    InputString = InputString.Replace("|", "&#124;")
    InputString = InputString.Replace("$", "&#36;")
    InputString = InputString.Replace("'", "&#39;")
    InputString = InputString.Replace("""", "&#92;")

    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.

0

精彩评论

暂无评论...
验证码 换一张
取 消