Using COM in asp.net project

H

HTM

Hi All,

I have a third party COM object done in C++. I want to use this COM object in my asp.net project. I'm able to add reference and initialize the object but when I'm getting a run-time error below:


Server Error in '/aspnet/fsc' Application.
--------------------------------------------------------------------------------

ERROR: Unable to Create an Instance of the Server
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: ERROR: Unable to Create an Instance of the Server

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET write access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

Source Error:


An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:


[UnauthorizedAccessException: ERROR: Unable to Create an Instance of the Server]
STEALTHRATERAPILib.AutoClass.GetMaritalStatus(Int32 nAgentID) +0
fsc.auto_profile.Page_Load(Object sender, EventArgs e) in f:\aspnet\fsc\auto_profile.aspx.cs:25
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731





--------------------------------------------------------------------------------

Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573


The ASP.Net account has been granted the access to the DLL but I'm still getting this error. Is there something else I'm missing when referencing the DLL? Should there be an Interop DLL to be added to the project in order for this to work?

Thanks very much
Henry
 
R

richlm

Hi

All you should need to do is to add the reference - VS.NET creates the interop dll for you, so you're not missing anything here. Below are some pointers that may help you...


The security context (user) that your code is running under is determined by two factors:
1. is anonymous access is enabled for the site/virtual-folder in IIS?
2. is impersonation enabled in web.config?


One way to find out which user needs access to the COM component is to add something like this just before your call:
....
IIdentity i = System.Threading.Thread.CurrentPrincipal.Identity;
System.Diagnostics.Debug.WriteLine(i.Name);
// call COM component
....

Does your COM component use any other files/folders?

If your web application runs with anything other than full trust, you may also run into code access security problems (because the COM component is unmanaged code which requires full trust) - but I think you will get a different exception if that was the case here.

Richard.
Hi All,

I have a third party COM object done in C++. I want to use this COM object in my asp.net project. I'm able to add reference and initialize the object but when I'm getting a run-time error below:


Server Error in '/aspnet/fsc' Application.
------------------------------------------------------------------------------

ERROR: Unable to Create an Instance of the Server
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: ERROR: Unable to Create an Instance of the Server

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET write access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

Source Error:


An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:


[UnauthorizedAccessException: ERROR: Unable to Create an Instance of the Server]
STEALTHRATERAPILib.AutoClass.GetMaritalStatus(Int32 nAgentID) +0
fsc.auto_profile.Page_Load(Object sender, EventArgs e) in f:\aspnet\fsc\auto_profile.aspx.cs:25
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731





------------------------------------------------------------------------------

Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573


The ASP.Net account has been granted the access to the DLL but I'm still getting this error. Is there something else I'm missing when referencing the DLL? Should there be an Interop DLL to be added to the project in order for this to work?

Thanks very much
Henry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top