Question

Can you call a vb.net api function using reflection from javascript code?

I just started playing around with reflection, I have this snippet of code that works, I want to change it to a javascript page.

Dim RawPlugin As Reflection.Assembly
RawPlugin = Reflection.Assembly.LoadFrom("C:\Inetpub\wwwroot\demo\MasterApplication\getSession\bin\Debug\getSession.dll")

Dim Instance As Object
Instance = RawPlugin.CreateInstance("getSession.class1", True, _
   Reflection.BindingFlags.Default, Nothing, Nothing, Nothing, Nothing)

theValue = Instance.getSessionValue(Session).ToString

Does anyone know if this is possible?

Was it helpful?

Solution

Client side code doesn't speak directly to server side code. If the information you are looking for is unaffected in between page requests by the user, then you have two options: output the server side value to the client with the page request (so it's value is inside a JavaScript variable on the page), or make it an ajax call. If the information could possibly be stale in between page requests, then you're only option is to return the value from an ajax call.

OTHER TIPS

In ASP.Net, the .Net code runs on your web server. Javascript runs on the user's computer, in their browser. That user might not even have Windows, let alone the .Net runtime.

For that matter, your user might not even have javascript enabled.

NO, you can't use reflections, or anything .Net for that matter, directly from javascript.

the soution:

you can create callbacks using ajax, to call a aspx page, that on page load, runs the code behind, that then creates the reflection in .net, and then passes the end result back to the javascript side, this works, i know this does... however this means that inside the project you need to have the callback page (needs to be compiled if there is any changes).

i guess what i need to do is [use JavaScript ajax to call a callback page that performs the reflection]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top