Microsoft KB Archive/305624

From BetaArchive Wiki
Knowledge Base


PRB: Cannot Host .NET User Controls in Internet Explorer 6.0 from File System

Article ID: 305624

Article Last Modified on 2/12/2007



APPLIES TO

  • Microsoft .NET Framework Software Development Kit 1.0 Service Pack 2
  • Microsoft .NET Framework Software Development Kit 1.0 Service Pack 2



This article was previously published under Q305624

SYMPTOMS

When you use a file protocol to open a Web page that hosts a .NET user control, a square container appears instead of the control.

CAUSE

By design, you cannot use the overloaded syntax for the <OBJECT> tag to load .NET user controls into Microsoft Internet Explorer from the file system because of security concerns. For example, you cannot use the following syntax:

<OBJECT id="Obj1" classid="Assembly.dll#FullNamespace.ControlName">
                

RESOLUTION

To load the assembly (the user control dynamic-link library [.dll] file) from the file system (local computer), you must follow these steps:

  1. Install the assembly in the Global Assembly Cache (GAC).
  2. Use the Regasm.exe tool to register the assembly.
  3. Host the assembly in Internet Explorer as if the assembly was a classic ActiveX control.

More specifically, you must follow these steps to host a .NET user control from the file system:

  1. Install the control in the Global Assembly Cache (GAC).For additional information about how to do this, click the article number below to view the article in the Microsoft Knowledge Base:

    315682 HOW TO: Install an Assembly into the Global Assembly Cache in Visual Studio .NET

    1. Use the Sn.exe tool to generate a cryptographic key pair (that is, a strong name). Sn.exe is located in the \Bin subdirectory of the directory where the .NET Framework Software Development Kit (SDK) is installed.

      Click Start, point to All Programs, point to Microsoft Visual Studio .NET, point to Visual Studio .NET Tools, and then click Visual Studio .NET Command Prompt. This automatically sets the environment to use Visual Studio .NET. You can then use Sn.exe from any directory.
    2. Add the assembly attribute to the AssemblyInfo.vb or the AssemblyInfo.cs file to associate the key that is generated to the current assembly. For example, if your key is MyKey.snk, add the following assembly attribute to the file:

      Visual C# .NET:

      [assembly: AssemblyKeyFile("C:\\GACDemo\\MyKey.snk")]
                                  

      Visual Basic .NET:

      <Assembly: AssemblyKeyFile("C:\GACDemo\MyKey.snk")>
                              
    3. Compile the project.
    4. Use the Gacutil tool or drag the .dll file to the C:\[SystemRoot]\Assembly folder to install the .dll file into GAC.
  2. Follow these steps to register the control:
    1. Open the Visual Studio .NET command prompt from Visual Studio .NET Tools to automatically set the environment to use Visual Studio .NET.
    2. Use Regasm.exe to register the control. For example, use the following syntax at the Visual Studio .NET command prompt:

      regasm mytest.dll

      NOTE: The Regasm.exe tool is located in .NET Framework directory.
  3. In your Hypertext Markup Language (HTML) page, use the classic ActiveX control syntax for the <OBJECT> tag. For example:

    <OBJECT ID="idtest" CLASSID="CLSID:9F769412-6736-39DD-9B29-DEF814E32B26" CODEBASE="mytest.dll#-1,-1,-1,-1">
                        


REFERENCES

For additional information about how to host .NET user controls in Internet Explorer, click the article number below to view the article in the Microsoft Knowledge Base:

317346 INFO: Native Versus COM-Callable .NET Controls in Internet Explorer


For more information about Dynamic DHTML and .NET, see the following MSDN Magazine article:

Host Secure, Lightweight Client-Side Controls in Microsoft Internet Explorer
http://msdn.microsoft.com/library/default.asp?url=/msdnmag/issues/02/01/UserCtrl/TOC.asp


For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:


Additional query words: ie6 usercontrol gac file protocol local machine ftp

Keywords: kbprb kbctrl KB305624