Signed Assembly usercontrol in webform
Hi People ,
I am newbie to embedding a Dotnet Assembly based control in an Aspx page so it behaves like a Com object.I am trying to display a Windows UserControl in a ASP.NET . I have previously managed to do so when my class library(Which contains usercontrols) was unsigned . Inorder to get my code full trust access on my own machine through IIS still , according to some info on web i decided to Strong name the assembly .Now the problem is that the same activex object (User control) work fine in a winform project but if i was to embed it in a ASP>NET page it does n't show up . I have ran Ragasm tool and gacutil.exe to do there jobs . I am sure the assembly is in the cache as well as upon running the command Gacutil /ldl
I get the following output
Microsoft (R) .NET Global Assembly Cache Utility. Version 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.
The cache of downloaded files contains the following entries:
ActiveXDotNet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=987ccc4a
78937cc0, Custom=null
ActiveXDotNet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=987ccc4a
78937cc0, Custom=null
ActiveXDotNet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=987ccc4a
78937cc0, Custom=null
ActiveXDotNet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=987ccc4a
78937cc0, Custom=null
ActiveXDotNet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=987ccc4a
78937cc0, Custom=null
Microsoft.VSDesigner, Version=7.0.5000.0, Culture=neutral, PublicKeyToke
n=b03f5f7f11d50a3a, Custom=null
Number of items = 6
I have set permissions everything permission for MyUserControlCodeGroup to everything
I know it 's security flaw but i just want my control to run for once and then i 'll try to narrow things down.
IIS is configured to provide Anonmous access with windows authentication check box enabled as well .
I looked up the classid for my control from windows registry and i am trying to use that in the webform following is my webform code
<%@ Page language="c#" Codebehind="Hardwaretest.aspx.cs" AutoEventWireup="false" Inherits="MyFirstActiveXObject.Hardwaretest" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Hardwaretest</title>
<META content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<META content="C#" name="CODE_LANGUAGE">
<META content="JavaScript" name="vs_defaultClientScript">
<META content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<BODY MS_POSITIONING="GridLayout">
<OBJECT id="HardwareDetector1" codeBase="http://localhost/ActiveXDotNet/bin/Debug/ActiveXDotNet.dll"
height="328" width="632" data="data:application/x-oleobject;base64,IGkzJfkDzxGP0ACqAGhvEzwhRE9DVFlQR SBIVE1MIFBVQkxJQyAiLS8vVzNDLy9EVEQgSFRNTCA0LjAgVHJ hbnNpdGlvbmFsLy9FTiI+DQo8SFRNTD48SEVBRD4NCjxNRVRBI Gh0dHAtZXF1aXY9Q29udGVudC1UeXBlIGNvbnRlbnQ9InRleHQ vaHRtbDsgY2hhcnNldD13aW5kb3dzLTEyNTIiPg0KPE1FVEEgY 29udGVudD0iTVNIVE1MIDYuMDAuMjkwMC4yNjI3IiBuYW1lPUd FTkVSQVRPUj48L0hFQUQ+DQo8Qk9EWT4NCjxQPiZuYnNwOzwvU D48L0JPRFk+PC9IVE1MPg0K"
classid="936DA01F-9ABD-4D9D-80C7-02AF85C822A8" name="HardwareDetector1" VIEWASTEXT>
</OBJECT>
<FORM id="Form1">
<INPUT id="Text1" style="WIDTH: 200px; HEIGHT: 22px" type="text" size="28" value="enter WMI Object Name here"
name="txt"><INPUT id="Button1" onclick="doScript();" type="button" value="Click me" name="Button1">
</FORM>
<SCRIPT language="javascript">
function doScript()
{
}
</SCRIPT>
</BODY>
</HTML>
The code for my usercontrol is
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Management;
using System.IO;
using System.Security;
using System.Security.Permissions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly:AllowPartiallyTrustedCallers]
namespace ActiveXDotNet
{ [Guid("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4")]
public interface AxHardwareDetector
{
}
/// <summary>
/// Summary description for HardwareDetector.
/// </summary>
///
[Guid("936DA01F-9ABD-4d9d-80C7-02AF85C822A8")]
public class HardwareDetector : System.Windows.Forms.UserControl,AxHardwareDetecto r
{
private System.Windows.Forms.Label label2;
private System.Windows.Forms.DataGrid datagrid1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button2;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public HardwareDetector()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitializeComponent call
Attribute AxHardwareDetectorAttribute = Attribute.GetCustomAttribute( typeof( AxHardwareDetector ), typeof( GuidAttribute ) );
// The Value property of GuidAttribute returns a string.
System.Console.WriteLine( "AxHardwareDetectorAttribute: " + ((GuidAttribute)AxHardwareDetectorAttribute).Value );
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label2 = new System.Windows.Forms.Label();
this.datagrid1 = new System.Windows.Forms.DataGrid();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.button2 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.d atagrid1)).BeginInit();
this.SuspendLayout();
//
// label2
//
this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label2.ForeColor = System.Drawing.Color.Brown;
this.label2.Location = new System.Drawing.Point(8, 116);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(136, 23);
this.label2.TabIndex = 13;
this.label2.Text = "Details";
//
// datagrid1
//
this.datagrid1.DataMember = "";
this.datagrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.datagrid1.Location = new System.Drawing.Point(8, 140);
this.datagrid1.Name = "datagrid1";
this.datagrid1.Size = new System.Drawing.Size(656, 264);
this.datagrid1.TabIndex = 17;
//
// comboBox1
//
this.comboBox1.Items.AddRange(new object[] {
"Win32_DiskDrive",
"Win32_OperatingSystem",
"Win32_Processor",
"Win32_ComputerSystem",
"Win32_StartupCommand",
"Win32_ProgramGroup",
"Win32_SystemDevices"});
this.comboBox1.Location = new System.Drawing.Point(8, 84);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(456, 21);
this.comboBox1.TabIndex = 16;
//
// button1
//
this.button1.Location = new System.Drawing.Point(480, 84);
this.button1.Name = "button1";
this.button1.TabIndex = 15;
this.button1.Text = "Show";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label1.ForeColor = System.Drawing.Color.Brown;
this.label1.Location = new System.Drawing.Point(8, 60);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(608, 23);
this.label1.TabIndex = 14;
this.label1.Text = "Select the win32 API or type in a new one. Then click on the \"Show\" button.";
//
// button2
//
this.button2.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.button2.Location = new System.Drawing.Point(576, 84);
this.button2.Name = "button2";
this.button2.TabIndex = 12;
this.button2.Text = "Cancel";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// HardwareDetector
//
this.Controls.Add(this.label2);
this.Controls.Add(this.datagrid1);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.button1);
this.Controls.Add(this.label1);
this.Controls.Add(this.button2);
this.Name = "HardwareDetector";
this.Size = new System.Drawing.Size(704, 464);
((System.ComponentModel.ISupportInitialize)(this.d atagrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
datagrid1.DataSource = GetStuff(comboBox1.Text);
}
public ArrayList GetStuff(string queryObject)
{
ManagementObjectSearcher searcher;
int i = 0;
ArrayList hd = new ArrayList();
try
{
searcher = new ManagementObjectSearcher("SELECT * FROM " + queryObject);
foreach(ManagementObject wmi_HD in searcher.Get())
{
i++;
PropertyDataCollection searcherProperties = wmi_HD.Properties;
foreach (PropertyData sp in searcherProperties)
{
hd.Add(sp);
}
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
return hd;
}
private void button2_Click(object sender, System.EventArgs e)
{
//this.Close();
}
}
}
Please suggest what am i doing wrong , cause for the life in me i cannot go with this wild goose chase i have been on since early hours of today .I am not sure where exactly the problem is , but i know it all started soon after i started following this tutorial on Microsoft's web site to make signed assembly.Any ideas or suggestions would be very highly appreciated .Thanxs in advance
Cheers :-)
Looney!
__________________
Looney!
|