Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / August 2004

Tip: Looking for answers? Try searching our database.

Impersonation and Path.GetTempPath()

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Oleg Ogurok - 25 Aug 2004 16:11 GMT
Hi all,

I have a ASP.NET app that uses Excel interop to save an .xls file on disk in
a temp folder and then read it back and e-mails it as an attachment.

The problem is deciding where to store the temp file. My web.config has
<identity impersonate="true" />

When I call System.IO.Path.GetTempPath(), it returns
C:\DOCUME~1\MYSERVER\ASPNET\LOCALS~1\Temp. However, when I try to save the
file, I get an error saying "Microsoft Office Excel cannot access the file."
It seems despite the impersonation, I still get the home dir of ASPNET user
instead of the user under which the IIS virtual directory is running. Is
there a more correct way of getting a temp path?

Thanks.

-Oleg.
bruce barker - 25 Aug 2004 17:04 GMT
impersonation only changes the thread's credentials, not the profile
associated with the process. a user profile is where temp, default printer,
etc settings are stored. in fact asp.net usually runs without a profile.

-- bruce (sqlwork.com)

> Hi all,
>
[quoted text clipped - 14 lines]
>
> -Oleg.
Phil Wilson - 25 Aug 2004 17:57 GMT
This is what the LoadUserProfile Win32 API is for - don't know if there's a
framework equivalent.
Signature

Phil Wilson [MVP Windows Installer]
----

> Hi all,
>
[quoted text clipped - 14 lines]
>
> -Oleg.
Carlos Perez - 29 Aug 2004 02:25 GMT
FWIW...

I also found that a call to System.IO.Path.GetTempFileName() will throw an
IOExceception: "The directory name is invalid."

This happens with impersonation turned on and anonymous access turned off
under Windows 2000 (IIS 5).  The temp directory is C:\Documents and
Settings\<machine>\ASPNET\Local Settings\Temp\ and the impersonated user
does not have create & write access to this directory.  My solution was to
permit Everyone full control in Temp.  I find it odd that with impersonation
turned on you get a temporary directory you can't write to, but I think this
is an artifict of the 2 layer security model with IIS and ASP.NET.

Note that on Windows 2003 (IIS 6) the default behavior is different.  Calls
to GetTempPath() will yield C:\WINDOWS\TEMP\.  Since directory permissions
are usually open to authenticated users, you application would probably work
without changing temp directory permissions.

Thx, Carlos

> This is what the LoadUserProfile Win32 API is for - don't know if there's a
> framework equivalent.
[quoted text clipped - 19 lines]
> >
> > -Oleg.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.