473,406 Members | 2,273 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

CoInitializeSecurity in ASP.NET

Hello,

i try to get access to a local virtual server object.
I have a aspx page with a button and textbox, this is the code:

public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btnFillBox;
protected System.Web.UI.WebControls.TextBox txtHost;
protected System.Web.UI.WebControls.Label Label1;

public enum RpcAuthnLevel
{
Default = 0,
None = 1,
Connect = 2,
Call = 3,
Pkt = 4,
PktIntegrity = 5,
PktPrivacy = 6
}

public enum RpcImpLevel
{
Default = 0,
Anonymous = 1,
Identify = 2,
Impersonate = 3,
Delegate = 4
}

public enum EoAuthnCap
{
None = 0x00,
MutualAuth = 0x01,
StaticCloaking= 0x20,
DynamicCloaking= 0x40,
AnyAuthority= 0x80,
MakeFullSIC= 0x100,
Default= 0x800,
SecureRefs= 0x02,
AccessControl= 0x04,
AppID= 0x08,
Dynamic= 0x10,
RequireFullSIC= 0x200,
AutoImpersonate= 0x400,
NoCustomMarshal= 0x2000,
DisableAAA= 0x1000
}

[DllImport("ole32.dll")]
public static extern int CoInitializeSecurity( IntPtr pVoid, int
cAuthSvc,IntPtr asAuthSvc, IntPtr pReserved1, RpcAuthnLevel level,
RpcImpLevel impers,IntPtr pAuthList, int dwCapabilities, IntPtr
pReserved3 );

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form
Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnFillBox.Click += new System.EventHandler
(this.btnFillBox_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

[STAThread]
private void btnFillBox_Click(object sender, System.EventArgs e)
{
this.txtHost.Text = "";
CoInitializeSecurity( IntPtr.Zero, -1, IntPtr.Zero,
IntPtr.Zero,RpcAuthnLevel.PktIntegrity ,
RpcImpLevel.Identify,IntPtr.Zero, 0x40, IntPtr.Zero );

VMVirtualServerClass vs;
vs = new VMVirtualServerClass();
this.txtHost.Text = vs.Version;

}
}
}
I always get a "Access denied" on vs = new VMVirtualServerClass();
I have tried different combinations for CoInitializeSecurity, but with no
success.

Does anybody has experience of accessing a Virtual Server (COM) through
ASP.NET ? Or is there another usable interface to VS ?

Many thanks

Clas

--
The light at the end of the tunnel,
was switch off due to high costs.
Nov 16 '05 #1
9 6299
Clas,

Why are you calling CoInitializeSecurity? Since you are calling a COM
object, are you setting the ASPCompat attribute to true? Also, does the
object do anything that requires file or registry access?

Chances are you will have to impersonate a user that has the rights to
access virtual server.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Clas Hortien" <ho*****@hotmail.com> wrote in message
news:ci**********@news1.wdf.sap-ag.de...
Hello,

i try to get access to a local virtual server object.
I have a aspx page with a button and textbox, this is the code:

public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btnFillBox;
protected System.Web.UI.WebControls.TextBox txtHost;
protected System.Web.UI.WebControls.Label Label1;

public enum RpcAuthnLevel
{
Default = 0,
None = 1,
Connect = 2,
Call = 3,
Pkt = 4,
PktIntegrity = 5,
PktPrivacy = 6
}

public enum RpcImpLevel
{
Default = 0,
Anonymous = 1,
Identify = 2,
Impersonate = 3,
Delegate = 4
}

public enum EoAuthnCap
{
None = 0x00,
MutualAuth = 0x01,
StaticCloaking= 0x20,
DynamicCloaking= 0x40,
AnyAuthority= 0x80,
MakeFullSIC= 0x100,
Default= 0x800,
SecureRefs= 0x02,
AccessControl= 0x04,
AppID= 0x08,
Dynamic= 0x10,
RequireFullSIC= 0x200,
AutoImpersonate= 0x400,
NoCustomMarshal= 0x2000,
DisableAAA= 0x1000
}

[DllImport("ole32.dll")]
public static extern int CoInitializeSecurity( IntPtr pVoid, int
cAuthSvc,IntPtr asAuthSvc, IntPtr pReserved1, RpcAuthnLevel
level,
RpcImpLevel impers,IntPtr pAuthList, int dwCapabilities, IntPtr
pReserved3 );

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form
Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnFillBox.Click += new System.EventHandler
(this.btnFillBox_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

[STAThread]
private void btnFillBox_Click(object sender, System.EventArgs e)
{
this.txtHost.Text = "";
CoInitializeSecurity( IntPtr.Zero, -1, IntPtr.Zero,
IntPtr.Zero,RpcAuthnLevel.PktIntegrity ,
RpcImpLevel.Identify,IntPtr.Zero, 0x40, IntPtr.Zero );

VMVirtualServerClass vs;
vs = new VMVirtualServerClass();
this.txtHost.Text = vs.Version;

}
}
}
I always get a "Access denied" on vs = new VMVirtualServerClass();
I have tried different combinations for CoInitializeSecurity, but with no
success.

Does anybody has experience of accessing a Virtual Server (COM) through
ASP.NET ? Or is there another usable interface to VS ?

Many thanks

Clas

--
The light at the end of the tunnel,
was switch off due to high costs.

Nov 16 '05 #2
Have you read this already?
http://msdn.microsoft.com/library/de...com_object.asp

That has a sample of calling virtual server.

--
Girish Bharadwaj
http://msmvps.com/gbvb
"Clas Hortien" <ho*****@hotmail.com> wrote in message
news:ci**********@news1.wdf.sap-ag.de...
Hello,

i try to get access to a local virtual server object.
I have a aspx page with a button and textbox, this is the code:

public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btnFillBox;
protected System.Web.UI.WebControls.TextBox txtHost;
protected System.Web.UI.WebControls.Label Label1;

public enum RpcAuthnLevel
{
Default = 0,
None = 1,
Connect = 2,
Call = 3,
Pkt = 4,
PktIntegrity = 5,
PktPrivacy = 6
}

public enum RpcImpLevel
{
Default = 0,
Anonymous = 1,
Identify = 2,
Impersonate = 3,
Delegate = 4
}

public enum EoAuthnCap
{
None = 0x00,
MutualAuth = 0x01,
StaticCloaking= 0x20,
DynamicCloaking= 0x40,
AnyAuthority= 0x80,
MakeFullSIC= 0x100,
Default= 0x800,
SecureRefs= 0x02,
AccessControl= 0x04,
AppID= 0x08,
Dynamic= 0x10,
RequireFullSIC= 0x200,
AutoImpersonate= 0x400,
NoCustomMarshal= 0x2000,
DisableAAA= 0x1000
}

[DllImport("ole32.dll")]
public static extern int CoInitializeSecurity( IntPtr pVoid, int
cAuthSvc,IntPtr asAuthSvc, IntPtr pReserved1, RpcAuthnLevel level, RpcImpLevel impers,IntPtr pAuthList, int dwCapabilities, IntPtr
pReserved3 );

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form
Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnFillBox.Click += new System.EventHandler
(this.btnFillBox_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

[STAThread]
private void btnFillBox_Click(object sender, System.EventArgs e)
{
this.txtHost.Text = "";
CoInitializeSecurity( IntPtr.Zero, -1, IntPtr.Zero,
IntPtr.Zero,RpcAuthnLevel.PktIntegrity ,
RpcImpLevel.Identify,IntPtr.Zero, 0x40, IntPtr.Zero );

VMVirtualServerClass vs;
vs = new VMVirtualServerClass();
this.txtHost.Text = vs.Version;

}
}
}
I always get a "Access denied" on vs = new VMVirtualServerClass();
I have tried different combinations for CoInitializeSecurity, but with no
success.

Does anybody has experience of accessing a Virtual Server (COM) through
ASP.NET ? Or is there another usable interface to VS ?

Many thanks

Clas

--
The light at the end of the tunnel,
was switch off due to high costs.

Nov 16 '05 #3
Hi Nicholas:

Actually, in this case the documentation Girish pointed to says:

"The multithreaded apartment model should be used for applications
using the Virtual Server COM interfaces. Using the single-threaded
apartment model with the Virtual Server COM interface can
significantly affect the Virtual Server system's performance."

In which case the OP would not want to set aspcompat="true".

--
Scott
http://www.OdeToCode.com
On Mon, 20 Sep 2004 09:09:28 -0400, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.com> wrote:
Clas,

Why are you calling CoInitializeSecurity? Since you are calling a COM
object, are you setting the ASPCompat attribute to true? Also, does the
object do anything that requires file or registry access?

Chances are you will have to impersonate a user that has the rights to
access virtual server.

Hope this helps.


Nov 16 '05 #4
Hi Clas:

ASP.NET calls the CoInitializeSecurity API when it starts up, since
you can only call this API once during the life of a process, you
won't be able to change any settings from your code.

You might consider impersonating a user with priviledges to the
object. Use DCOMCNFG to see what permissions are in effect.

--
Scott
http://www.OdeToCode.com
On 20 Sep 2004 12:28:23 GMT, Clas Hortien <ho*****@hotmail.com> wrote:
Hello,

i try to get access to a local virtual server object.
I have a aspx page with a button and textbox, this is the code:

public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btnFillBox;
protected System.Web.UI.WebControls.TextBox txtHost;
protected System.Web.UI.WebControls.Label Label1;

public enum RpcAuthnLevel
{
Default = 0,
None = 1,
Connect = 2,
Call = 3,
Pkt = 4,
PktIntegrity = 5,
PktPrivacy = 6
}

public enum RpcImpLevel
{
Default = 0,
Anonymous = 1,
Identify = 2,
Impersonate = 3,
Delegate = 4
}

public enum EoAuthnCap
{
None = 0x00,
MutualAuth = 0x01,
StaticCloaking= 0x20,
DynamicCloaking= 0x40,
AnyAuthority= 0x80,
MakeFullSIC= 0x100,
Default= 0x800,
SecureRefs= 0x02,
AccessControl= 0x04,
AppID= 0x08,
Dynamic= 0x10,
RequireFullSIC= 0x200,
AutoImpersonate= 0x400,
NoCustomMarshal= 0x2000,
DisableAAA= 0x1000
}

[DllImport("ole32.dll")]
public static extern int CoInitializeSecurity( IntPtr pVoid, int
cAuthSvc,IntPtr asAuthSvc, IntPtr pReserved1, RpcAuthnLevel level,
RpcImpLevel impers,IntPtr pAuthList, int dwCapabilities, IntPtr
pReserved3 );

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form
Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnFillBox.Click += new System.EventHandler
(this.btnFillBox_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

[STAThread]
private void btnFillBox_Click(object sender, System.EventArgs e)
{
this.txtHost.Text = "";
CoInitializeSecurity( IntPtr.Zero, -1, IntPtr.Zero,
IntPtr.Zero,RpcAuthnLevel.PktIntegrity ,
RpcImpLevel.Identify,IntPtr.Zero, 0x40, IntPtr.Zero );

VMVirtualServerClass vs;
vs = new VMVirtualServerClass();
this.txtHost.Text = vs.Version;

}
}
}
I always get a "Access denied" on vs = new VMVirtualServerClass();
I have tried different combinations for CoInitializeSecurity, but with no
success.

Does anybody has experience of accessing a Virtual Server (COM) through
ASP.NET ? Or is there another usable interface to VS ?

Many thanks

Clas


Nov 16 '05 #5
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
news:OG**************@TK2MSFTNGP15.phx.gbl:
Clas,

Why are you calling CoInitializeSecurity? Since you are calling a COM
object, are you setting the ASPCompat attribute to true? Also, does the
object do anything that requires file or registry access?

Chances are you will have to impersonate a user that has the rights to
access virtual server.

Hope this helps.


I have tried to set ASPCompat=true but with no difference.
I have local admin rights (yes, i know what i'm doing ;-)), but i still
get the access denied error. The object representing the local
virtual server service and i should be able to do anything with
it as a local admin.

Thanks

Clas


--
The light at the end of the tunnel,
was switch off due to high costs.
Nov 16 '05 #6
"Girish Bharadwaj" <gi*****@mvps.org> wrote in
news:#w**************@tk2msftngp13.phx.gbl:
Have you read this already?
http://msdn.microsoft.com/library/de...en-us/msvs/msv
s/connecting_to_the_virtual_server_com_object.asp

That has a sample of calling virtual server.


This was the example, where i got the code from, there they use the
CoInitializeSecurity. The only difference is, that the example is a Console
Application and i want to use a ASP page.
--
The light at the end of the tunnel,
was switch off due to high costs.
Nov 16 '05 #7
Doh. How could I miss that!

--
Girish Bharadwaj
http://msmvps.com/gbvb
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:4u********************************@4ax.com...
Hi Clas:

ASP.NET calls the CoInitializeSecurity API when it starts up, since
you can only call this API once during the life of a process, you
won't be able to change any settings from your code.

You might consider impersonating a user with priviledges to the
object. Use DCOMCNFG to see what permissions are in effect.

--
Scott
http://www.OdeToCode.com
On 20 Sep 2004 12:28:23 GMT, Clas Hortien <ho*****@hotmail.com> wrote:
Hello,

i try to get access to a local virtual server object.
I have a aspx page with a button and textbox, this is the code:

public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btnFillBox;
protected System.Web.UI.WebControls.TextBox txtHost;
protected System.Web.UI.WebControls.Label Label1;

public enum RpcAuthnLevel
{
Default = 0,
None = 1,
Connect = 2,
Call = 3,
Pkt = 4,
PktIntegrity = 5,
PktPrivacy = 6
}

public enum RpcImpLevel
{
Default = 0,
Anonymous = 1,
Identify = 2,
Impersonate = 3,
Delegate = 4
}

public enum EoAuthnCap
{
None = 0x00,
MutualAuth = 0x01,
StaticCloaking= 0x20,
DynamicCloaking= 0x40,
AnyAuthority= 0x80,
MakeFullSIC= 0x100,
Default= 0x800,
SecureRefs= 0x02,
AccessControl= 0x04,
AppID= 0x08,
Dynamic= 0x10,
RequireFullSIC= 0x200,
AutoImpersonate= 0x400,
NoCustomMarshal= 0x2000,
DisableAAA= 0x1000
}

[DllImport("ole32.dll")]
public static extern int CoInitializeSecurity( IntPtr pVoid, int
cAuthSvc,IntPtr asAuthSvc, IntPtr pReserved1, RpcAuthnLevel level, RpcImpLevel impers,IntPtr pAuthList, int dwCapabilities, IntPtr pReserved3 );

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form
Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnFillBox.Click += new System.EventHandler
(this.btnFillBox_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

[STAThread]
private void btnFillBox_Click(object sender, System.EventArgs e)
{
this.txtHost.Text = "";
CoInitializeSecurity( IntPtr.Zero, -1, IntPtr.Zero,
IntPtr.Zero,RpcAuthnLevel.PktIntegrity ,
RpcImpLevel.Identify,IntPtr.Zero, 0x40, IntPtr.Zero );

VMVirtualServerClass vs;
vs = new VMVirtualServerClass();
this.txtHost.Text = vs.Version;

}
}
}
I always get a "Access denied" on vs = new VMVirtualServerClass();
I have tried different combinations for CoInitializeSecurity, but with no
success.

Does anybody has experience of accessing a Virtual Server (COM) through
ASP.NET ? Or is there another usable interface to VS ?

Many thanks

Clas

Nov 16 '05 #8
Scott Allen <bitmask@[nospam].fred.net> wrote in
news:4u********************************@4ax.com:
Hi Clas:

ASP.NET calls the CoInitializeSecurity API when it starts up, since
you can only call this API once during the life of a process, you
won't be able to change any settings from your code.

You might consider impersonating a user with priviledges to the
object. Use DCOMCNFG to see what permissions are in effect.


Hi Scott,

i checked the DCOMCNFG, but with no difference:

- the authentication level is default, "none" doesn't work either
- Location is local computer
- at security i played around with different user, but with no
result
- at identity i tried a local admin, but no result

Many thanks

Clas
Nov 16 '05 #9
So, you are running the form as ASPNET user. Does that user have access to
that functionality of Virtual Server? If not, you might have to modify those
permissions.

Or, you might be able to use <identity> in web.config for this particular
project and set impersonate=true (and probably provide user name and
password which has access to that object).

--
Girish Bharadwaj
http://msmvps.com/gbvb
"Clas Hortien" <ho*****@hotmail.com> wrote in message
news:ci**********@news1.wdf.sap-ag.de...
Scott Allen <bitmask@[nospam].fred.net> wrote in
news:4u********************************@4ax.com:
Hi Clas:

ASP.NET calls the CoInitializeSecurity API when it starts up, since
you can only call this API once during the life of a process, you
won't be able to change any settings from your code.

You might consider impersonating a user with priviledges to the
object. Use DCOMCNFG to see what permissions are in effect.


Hi Scott,

i checked the DCOMCNFG, but with no difference:

- the authentication level is default, "none" doesn't work either
- Location is local computer
- at security i played around with different user, but with no
result
- at identity i tried a local admin, but no result

Many thanks

Clas

Nov 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Trokey | last post by:
I am having a serious problem connecting to out-of-process COM objects in my windows service application. Whenever I try to create an instance of the COM object, a second instance of the COM server...
4
by: Heliotic | last post by:
Hi everyone, Currently I am working on an application that will perform a remote scan of a specified server using the following code: Type t = Type.GetTypeFromProgID(...
2
by: Stephen Corey | last post by:
How can I access the hardware information of a system, like hard drive(s) model & serial numbers, video card model, etc...? Thanks!
2
by: Mezz | last post by:
Microsoft has a page titled 'Connecting to the Virtual Server COM Object' I'd expect this to work out of the chute but I am having issues with the (surprise surprise) call to...
9
by: DrBonzo | last post by:
In order to get events back from a DCOM server (an embedded device running Windows CE), I seem to have to turn off security for my process. To do this, I'm saying: int ret =...
1
by: Huayang Xia | last post by:
I'd like to call pythoncom.CoInitializeSecurity with a PySecurityDescriptor object to set the process-wide security values. But I'm not able to find a way to let the code go through. I have read...
2
by: aarthi28 | last post by:
Hi, I have this code that I am trying to compile, but I am getting the following errors 'CoInitializeSecurity': identifier not found 'EOAC_NONE' : undeclared identifier I have pasted the...
6
stormrider
by: stormrider | last post by:
I was searching through MSDN pages. I've end up here; http://msdn2.microsoft.com/en-us/library/aa390422.aspx But when I tried to compile the code given below the page, I get this error;...
11
by: JCav | last post by:
I need to call a COM object from a remote machine using C#. I also need to pass on a different userID and password to the call. Has anyone done this? I've used Java to do this using JIntegra, but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.