Using a c# assembly client side

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I want to use one of my c# assemblies on the client browser (IE), say using
javascript to call it.

I have seen loads of people asking how they can host a WinForms control in
IE but all I want to do is call a few methods in my assembly which do not
have or need a UI.

The <object> tag seems to play a big role here but I haven't managed to get
it either to download the assembly or be callable from client script. Do I
need to do anything special in the c# assembly that will get downloaded? So
far its just a normal class library.

The client machines are all IE6 and can have the framework installed on them
too.

Any help would be much appreciated.

Regards
 
I have seen loads of people asking how they can host a WinForms control in
IE but all I want to do is call a few methods in my assembly which do not
have or need a UI.

Ever wonder why you haven't seen loads of people asking about what you want
to do? There is a reason. It's not remotely possible.

It helps to understand your programming environment. Otherwise, stick to
ASP, VBScript, and VBA.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
Hi Gravy,
I want to use one of my c# assemblies on the client browser (IE), say using
javascript to call it.

It is possible, but generally not advisable. The assembly would be
subject to CAS, and depending which zone the assembly was loaded from,
it might might have very few permissions. Also, it couldn't reference
any other assembly not reachable to the client. But, I threw togheter a
small example for you.

This the HTML code:

<html>
<script>
function ChangeCalc()
{
sum.value = simpleCalculator.Add(input1.value, input2.value);
}

</script>

<body>

<object id="simpleCalculator"
classid="http:EasyCalc.dll#EasyCalc.Calc"
<param name="Text" value="Simple Control">
</object>

<br>
<input type="text" id="input1"> +
<input type="text" id="input2"> =
<input type="text" id="sum" readonly="true">
<input type="button" value="Calc" onclick="ChangeCalc()">
<br>
</body>

</html>

And the C# code looks like this:

using System;

namespace EasyCalc
{
public class Calc
{
public Calc()
{
}

public int Add(int arg1, int arg2)
{
return arg1 + arg2;
}
}
}

The example above is runnable in the local intranet zone at the very
least (if you haven't changed any of the default permission settings on
the local intranet zone).

HTH,
Jonas
 
Thank you Jonas, hopefully Kevin will read your reply too!

This is was I was thinking but I never got it to work. I wasn't sure whether
the assembly I wanted to reference need any special attributes applied, like
Guids etc.

I'll give it another go anyway.

Thanks again.
 
No, David, I didn't intend for it to sound rude. Thank you for your kind
response, however. I'm afraid my bedside manner is still in beta.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
I hope I was wrong, Gravy. But I doubt it. Let us know. I don't like being
wrong, so I appreciate finding out when I am.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
here's a link on this:
http://forums.devarticles.com/archive/t-4583

I think that a WinForm control added to a page this way will have
permission to call a web service at the same web site it came from. This
would seem to be similar to a Smart Client app.

I haven't tried it, though. And it may only work with IE.

Eric
 
Hey Guys,

Thanks for all your help. The good news is that I have a very simple example
working now. I think one think I was doing wrong in the first place is not
placing the dll (the one referenced in the object tag) in the application
folder (not the BIN folder). As soon as I put it in the same folder as the
aspx file it started working.

Now, I shall try doing some usfull work and see how far I can get.
 
It worked ok. However, as described in the link you gave me I too had
security exceptions because my client side c# assembly wanted to call a COM
component. I had to use the framework wizards to adjust the .NET security and
give local intranet full trust.

Does anyone know if this is possible to set this setting through active
directory policy?

Thanks for all your help

Graham
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top