• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

cant instantiate excel in asp

hello experts,
i am developing an ASP.NET app.  on the server side i need to instantiate an instance of excel.  i have referenced the xp pias.  --------------------------------------------------------------------------------
here is my code that does the instantiation:

Public Class WebForm1 : Inherits System.Web.UI.Page
  Dim oExl As Microsoft.Office.Interop.Excel.Application

  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    oExl = New Microsoft.Office.Interop.Excel.ApplicationClass
  End Sub

  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

  End Sub

  Private designerPlaceholderDeclaration As System.Object

  Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    InitializeComponent()
  End Sub
End Class

--------------------------------------------------------------------------------
here is the error message:

Access is denied.
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: Access is denied.

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:


Line 4:  
Line 5:    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Line 6:      oExl = New Microsoft.Office.Interop.Excel.ApplicationClass
Line 7:      oExl.Visible = True
Line 8:    End Sub
 

Source File: c:\inetpub\wwwroot\CommissionWebInterface\WebForm1.aspx.vb    Line: 6

Stack Trace:


[UnauthorizedAccessException: Access is denied.]
   CommissionWebInterface.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\CommissionWebInterface\WebForm1.aspx.vb:6
   System.Web.UI.Control.OnLoad(EventArgs e)
   System.Web.UI.Control.LoadRecursive()
   System.Web.UI.Page.ProcessRequestMain()
--------------------------------------------------------------------------------------
any help is appreciated.
thanks
 
0
comppgmr
Asked:
comppgmr
1 Solution
 
rubixxcubeCommented:
This is a permissions issue for the ASP.NET user on your machine.  This user needs access to the folder that excel is launching from.  Unfortuantely i do not know off the top of my head what that folder is.  However here are 2 solutions that will work.
Make the ASP.NET user account on your machine an administrator, restart IIS and that will fix the problem.
The other option is to look into using impersonation.  
Here is a link to a good article from microsoft that explains access priveleges for the aspnet user and impersonation

http://support.microsoft.com/default.aspx?scid=kb;en-us;317012

The Most correct solution would be to find the folder the ASPNET user needs access to and soley grant permissions on that folder as opposed to making the user and admin.

Ruby
0
 
comppgmrAuthor Commented:
thanks rubixxcube,
using adding the aspnet account via dcomcnfg for the excel app and restarting iis fixed the problem.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now