System.UnauthorizedAccessException: Access is denied

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

In one of our ASP.NET Application web form we are using the
Microsoft.Office.Interop.Word COM DLL. We need to read some word documents
and create rtf files and merge them together into one doc file.

On click of a button the the word application com dll is getting activated,
but wehn we do this on a Windows Server 2003 machine we are getting the
following error.

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.

The COM DLL Microsoft.Word.Document has been given allow permission to the
ASPNET user account.

Can somebody help in setting the right permissions or finding a solution for
this.

This error in generated where the code has the following line
newApp = New Word.Application

Code:
Imports System.Runtime.InteropServices
Imports Word = Microsoft.Office.Interop.Word
Imports Office = Microsoft.Office.Core

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim newApp As Word.ApplicationClass

Dim source As Object = Server.MapPath("/site/Docs/" & sFileName)
Dim target As Object = Server.MapPath("/site/Docs/" & "temDocfile.rtf")

Dim unKnown As Object = Type.Missing

newApp = New Word.Application

newApp.Visible = True
newApp.Documents.Open(source, unKnown, unKnown, unKnown, unKnown,
unKnown, unKnown, unKnown, unKnown, unKnown, unKnown, unKnown, unKnown,
unKnown, unKnown)

Dim objformat As Object = Word.WdSaveFormat.wdFormatRTF

newApp.ActiveDocument.SaveAs(target, objformat, unKnown, unKnown,
unKnown, unKnown, unKnown, unKnown, unKnown, unKnown, unKnown, unKnown,
unKnown, unKnown, unKnown, unKnown)

newApp.ActiveDocument.Close(unKnown, unKnown, unKnown)

newApp.Quit(unKnown, unKnown, unKnown)
newApp = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject(newApp)
newApp = Nothing

End Sub

This code provided is for a testing page we had created where we are trying
to open a word document file and save that as a rtf file.

The folder where these files are opened from and closed have full
permissions to the ASPNet user account.
 
Back
Top