Microsoft KB Archive/305624

= 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  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: 



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:  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

 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.  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(&quot;C:\\GACDemo\\MyKey.snk&quot;)] Visual Basic .NET:   Compile the project. Use the Gacutil tool or drag the .dll file to the C:\[SystemRoot]\Assembly folder to install the .dll file into GAC.</li></ol> </li> Follow these steps to register the control: <ol style="list-style-type: lower-alpha;"> Open the Visual Studio .NET command prompt from Visual Studio .NET Tools to automatically set the environment to use Visual Studio .NET.</li> 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.</li></ol> </li>  In your Hypertext Markup Language (HTML) page, use the classic ActiveX control syntax for the <OBJECT> tag. For example: <OBJECT ID=&quot;idtest&quot; CLASSID=&quot;CLSID:9F769412-6736-39DD-9B29-DEF814E32B26&quot; CODEBASE=&quot;mytest.dll#-1,-1,-1,-1&quot;> </li></ol>

<div class="references_section">