Access Denied

  • Thread starter Deepankar Raizada
  • Start date
D

Deepankar Raizada

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

G P Zob (Capt)

Erm... I have the same problem...
My asp.net application has a section of code that picks up some data from a
sql database and then uses word to open a .dot template and then populate the
document with the data and then saves it to a subdirectory of the web site
for download by the client. On my development machine I have XP pro .NET fx
1.1.4322.2032 and word 2003 (11.6359.6408) SP1 The development machine
originally threw up the error that Deepanker talks about, and I am currently
doing a deployment study using virtual pc

Oh I was going to ask if anyone knows how to get this to work as well (I
originally got it to work on the development PC but I'd forgotten how.
However I have just got it to work on a win 2000 Server!!)

Don't know which part of this is the bit that did the trick but I have so
far:
Given the ASPNET account FULL CONTROL of the whole C:\program files\office
folder, FULL CONTROL of the folder containing the web application, set the
trust level for the dll in the bin folder of the web app to maximum, made the
ASPNET account a member of the Administrators Group. That seems to have done
it.

I now need to start undoing this to see which of these things was the
important one.
If anyone knows which one it was I'd appreciate it if they'd tell me.

G P Zob
 

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