473,320 Members | 1,957 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Impersonation and Path.GetTempPath()

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.
Nov 18 '05 #1
3 7676
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)
"Oleg Ogurok" <ol**@ogurok.com.ihatespammers.ireallydo.co> wrote in message
news:10*************@corp.supernews.com...
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.

Nov 18 '05 #2
This is what the LoadUserProfile Win32 API is for - don't know if there's a
framework equivalent.
--
Phil Wilson [MVP Windows Installer]
----
"Oleg Ogurok" <ol**@ogurok.com.ihatespammers.ireallydo.co> wrote in message
news:10*************@corp.supernews.com...
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.

Nov 18 '05 #3
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
"Phil Wilson" <Ph*********@unisys.spamcom> wrote in message
news:Os**************@TK2MSFTNGP15.phx.gbl...
This is what the LoadUserProfile Win32 API is for - don't know if there's a framework equivalent.
--
Phil Wilson [MVP Windows Installer]
----
"Oleg Ogurok" <ol**@ogurok.com.ihatespammers.ireallydo.co> wrote in message news:10*************@corp.supernews.com...
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.


Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Glenn A. Harlan | last post by:
Why am I receiving the below error when calling - Path.GetTempFileName() The directory name is invalid. Description: An unhandled exception occurred during the execution of the current web...
3
by: Chris | last post by:
Hello all, Here is my problem. I have a windows service (C#) that is supposed to move files from/to the local drive to/from a UNC share (\\domainserver\share). The service is running on a Win3k...
4
by: Bonj | last post by:
Hi I would like to know how to use impersonation, in order to write to a file on a network share. The user will be logging on to this web app, and will then click a button which will write to a...
1
by: techfuzz | last post by:
I'm posting my problem experience and solution I found here for other ASP.NET developers. I have a web application that uses Forms Authentication with Active Directory to control access. In...
3
by: Wm. Scott Miller | last post by:
What is the difference between using a username and password in the processmodel section vs using one in impersonation in the machine.config file? What are the advantages of each and what are the...
7
by: Bonj | last post by:
Hi I made a naff web application which uses the impersonation method in MSDN (can't find it now, but it basically revolves around creating a token by calling the LogonUser API, calling...
3
by: Steve Winter | last post by:
Hi, We have a number of websites running on an IIS6 server all running under their own seperate Anonymous Web account and ASP.Net is configured to Impersonate this account for each site for file...
27
by: vipleo | last post by:
I am having some issues, when I try to launch another process using Process.Start(ProcessStartInfo psi) on win xp sp2 box (Other versions of xp have no issue). Here is the detail. Main app...
2
by: vve | last post by:
Hi, when I compile the following statement.. this->_FileDirectory = System::IO::Path::GetTempPath(); I always get this error: Error 1 error C2039: 'GetTempPathW' : is not a member of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.