Access Denied

rita

Member
Joined
Jun 19, 2003
Messages
12
When I am saving a file on my server using asp.net application, it gives me "Access Denied", but I dont have the case on my localhost server.
knowing that I gave all users full permissions.
I use the word.application to save my file.

Dim WordApp As Word.ApplicationClass = New Word.ApplicationClass()
Dim aDoc1 As New Word.Document()
aDoc1.Activate()
aDoc1.Content.Text = FileContent
aDoc1.SaveAs(fileURL)
WordApp.Quit()
aDoc1 = Nothing
WordApp = Nothing

any help please.
Thanks in advance.
 
the FileURL contains the physical directory for the file.
ex: c:/folderName/fileName.doc
 
Function called ???

First ... make sure the file isnt already open by another Word. If you dont deallocate memory from Word objects, Word wont close correctly and will still have your document opened if you havent closed it.

Here is the function the clear them from memory.

Code:
Private Sub Nars(o as Object)
Try 
   System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
Catch

Finally 
    o = nothing
End Sub
 
Last edited by a moderator:
Which line of code actually generates the error? It may be a problem instantiating an instance of word.exe. I think you will need to grant permissions for aspnet to launch the application.

If you are running XP (and I think win2k and win2003) this should work. Start->Run->dcomcnfg - this should launch the component services tool.
Drill down to the correct computer and select DCOM config.
Look for the package that corresponds to MS Word (think it is called either Microsoft
Document or Microsoft Word Document).
Right click on it and bring up the property pages, then go to the security tab. Under launch permissions select customize and then edit. Finally add in the <machine name>\ASPNET account.

Not 100% on all of the above (dont have word or VS installed here) but it should be close enough to get you looking in the right direction.
 
I do what you suggested but nothing happen.
I want to inform you that when I used the streamwriter to save the file,
everything is fine and no "access denied " error.
But I cannot use it because streamwriter doesnt allow me to customize my document (font family etc.....).
So what I thing that is a problem between word and the MyServerName\ASPNET account.
what do you suggested?
thanks in advance.
 
The only thing I can think of is a dcom permission - if you have allowed the aspnet account launch permissions to word it should work.
 
I receive this error:
"QueryInterface for interface Word._Document failed"
any suggestion?
 
Even though the aspnet account has write rights you still need the IUSR_<machinename> to have write rights to the directory.
You might even try impersonation that allows the app to run inthe same user context as the account its impersonating instead of the asp app domain.

Also did you change your machine.config to reflect the system process type to system instead of machine ??

C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\CONFIG\machine.config

ie
Code:
 <processModel
            enable="true"
            timeout="Infinite"
            idleTimeout="Infinite"
            shutdownTimeout="0:00:05"
            requestLimit="Infinite"
            requestQueueLimit="5000"
            restartQueueLimit="10"
            memoryLimit="60"
            webGarden="false"
            cpuMask="0xffffffff"
            [COLOR=Red]userName="machine"[/COLOR]
            password="AutoGenerate"
            logLevel="Errors"
            clientConnectedCheck="0:00:05"
            comAuthenticationLevel="Connect"
            comImpersonationLevel="Impersonate"
            responseRestartDeadlockInterval="00:09:00"
            responseDeadlockInterval="00:03:00"
            maxWorkerThreads="25"
            maxIoThreads="25" />
 
Back
Top