cant instantiate excel in asp

Posted on 2005-05-12
Last Modified: 2008-01-09
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
  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)
any help is appreciated.
Question by:comppgmr
    LVL 2

    Accepted Solution

    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;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.


    Author Comment

    thanks rubixxcube,
    using adding the aspnet account via dcomcnfg for the excel app and restarting iis fixed the problem.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on could not pull conte…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    This video discusses moving either the default database or any database to a new volume.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now