Tech Off Thread

8 posts

Accessing a .NET dll in a HTML page

Back to Forum: Tech Off
  • User profile image
    MarDude

    Hello

    I am trying to provide an alternate front end to our ERP application.  This would require accessing the .net dlls from a browser.  I thought making a user control to wrap the objects in would work, but I can not get it to display. 

    I created a usercontrol with a textbox and a button.  I then checked the property "Register for COM interop".  I used the following code (with the dll copied to the same folder as the html file) but the usercontrol does not display.

    <object id="UserControl"
    classid="rotWI_ShopDataMaintenance.dll#rotWI_ShopDataMaintenance.UserControl"
    height="300" width="300">
    </object>

    I then followed this link Cannot Host .NET User Controls in Internet Explorer and ended up with this:

    <OBJECT ID="UserControl1" CLASSID="CLSID:9F769412-6736-39DD-9B29-DEF814E32B26" CODEBASE="rotWI_ShopDataMaintenance.dll#-1,-1,-1,-1" height="300" width="300">

    I am currently trying to determine what classid was assigned to my user control.  It did get farther, asked me to install something, but again, nothing happened.  I changed the classid to one I found in AssemblyInfo.vb but this did not help.

    I also tried fully qualifying the name, using a relative path and nothing works.  Anyone know what I am doing wrong?

  • User profile image
    cheong

    First, since you want it to run control on client side, there's no need to touch "Reference" or AssemblyInfo.vb.

    Then, read this and make sure you get everything correct.

    Finally, make sure users that need to access your page have the proper security settings set.

    Recent Achievement unlocked: Code Avenger Tier 4/6: You see dead program. A lot!
    Last modified
  • User profile image
    MarDude

    Thanks for your reply cheong.

    The first link talks about activating a control.  It describes a control that gets rendered but needs to be activated.  My control does not even appear.  So I do not even get far enough for that link to be of any use.  I hope I can get to the point where it becomes relevant.

    I think the problem is the class id.  I used the code from the example thinking that the id provided was some type of generic id.  But perhaps there is a specific id that it wants.  How do I get this information?

  • User profile image
    cheong

    After you've successfully registered your ActiveX assembly, run regedit.exe and find your UI control's class name, then get the CLSID key value there.

    For example, the CLSID for Adobe Reader is located at:
    HKEY_CLASSES_ROOT\AcroPDF.PDF\CLSID

    ******

    EDIT: Also, is the ActiveX assembly written in C# or VB.NET? 2 years ago I have written some COM+ class that failed to hook up in existing VB6 forms (as effort for transition towards .NET). Later found out that .NET v4.0 C# compiler doesn't generate correct code against COM+ exposed classes (VB.NET compiler does not have this issue), and I have to follow that article to add some custom register classes to add correct registry keys for complete component registration.

    I did remember that there's about 3 implementation at the web at that time, and one of them makes it work. Since I've changed company I don't have the source code with me to verify, you'd have to try them out and verify yourself.

    ******

    EDIT 2: I'm not sure if there's SP update that may have already fixed this issue, you may open MS Office, then in developer view, add a new form and try to add your component so as to check whether it works or not.

    Recent Achievement unlocked: Code Avenger Tier 4/6: You see dead program. A lot!
    Last modified
  • User profile image
    MarDude

    Thanks for your reply.

    I searched the registry again and found nothing under HKEY_CLASSES_ROOT.  I amnually ran regasm and it reported "RegAsm : warning RA0000 : No types were registered"

    I used the template for user control and noticed that the new control inherited from System.Windows.Forms.UserControl.  I tried to inherit from System.Web.UI.UserControl but htis control fails to render in the designer.  I also can not build the project because of this error "Error    1    Cannot register assembly "G:\Code\Intuitive Projects\Web Projects\rotWI_ShopDataMaintenance.dll". Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.    rotWI_ShopDataMaintenance

    I tried to find a tuitorial but everything talks about ASP.

    Any ideas?

  • User profile image
    cheong

    That's it. You control haven't correctly register itself as exposed interface. You should try to search the code I'm talking about in the previous post.

    System.Web.UI.UserControl is not designed to be displayed as ActiveX controls so it shouldn't be used. The System.Windows.Forms.UserControl is the correct one. As such, no AspNetHostingPermission is required.

     

    Recent Achievement unlocked: Code Avenger Tier 4/6: You see dead program. A lot!
    Last modified
  • User profile image
    LowKey247

    Nope

  • User profile image
    figuerres

    , MarDude wrote

    Hello

    I am trying to provide an alternate front end to our ERP application.  This would require accessing the .net dlls from a browser.  I thought making a user control to wrap the objects in would work, but I can not get it to display. 

    I created a usercontrol with a textbox and a button.  I then checked the property "Register for COM interop".  I used the following code (with the dll copied to the same folder as the html file) but the usercontrol does not display.

    <object id="UserControl"
    classid="rotWI_ShopDataMaintenance.dll#rotWI_ShopDataMaintenance.UserControl"
    height="300" width="300">
    </object>

    I then followed this link Cannot Host .NET User Controls in Internet Explorer and ended up with this:

    <OBJECT ID="UserControl1" CLASSID="CLSID:9F769412-6736-39DD-9B29-DEF814E32B26" CODEBASE="rotWI_ShopDataMaintenance.dll#-1,-1,-1,-1" height="300" width="300">

    I am currently trying to determine what classid was assigned to my user control.  It did get farther, asked me to install something, but again, nothing happened.  I changed the classid to one I found in AssemblyInfo.vb but this did not help.

    I also tried fully qualifying the name, using a relative path and nothing works.  Anyone know what I am doing wrong?

     

    well first it sounds to me like there is some confusion here on what you are doing.

    when we talk about asp.net the term "user control" means that it is some code and markup that run on the server and send html to the browser.

    if you have a dll that does server side stuff you can use a usercontrol on the server to attach it to a page.

    if you have code that runs on the client pc in the browser and it is in a dll then it needs to be an ActiveX dll.

    in general client side dll's should not be used. for example a client like an iPad or a windows 8 ie session from the "metro" UI will not run activex dll's

    do you have code that runs on the server or on the client ?

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.