473,394 Members | 2,100 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,394 software developers and data experts.

Temporary user files under IIS - FAQ?

What's the usual way of handling temporary user files under ASP.NET running
on IIS? On a normal Windows client program, you'd probably store the
documents in the %TEMP% folder. However, aren't all users running under the
same ASPNET account so they're sharing the same TEMP folder? Also, you
really want them within the web-site folder so that normal HTML <IMG> tags
can be used.

We're using a temporary file to hold a user's photograph. This photograph is
stored in a SQL database as an IMAGE column. When the record is opened, we
need to create the temporary file with the same file name so that if the
user right-clicks, the default file name is correct, i.e. the original.

At the moment, we've created a User folder in the web site and build a
unique path using the session ID like this:

c:\inetpub\wwwroot\ourwebsite\users\37873827387283 \porky.jpg

Where 37873827387283 is the session ID. It works but doesn't feel quite
right :-) We also have to manually grant ASPNET write access to the Users
folder.

Any better ideas?

Thanks, Rob.
Nov 19 '05 #1
6 1659
I think your approach is wrong. You can write files directly to the
response stream ( and give them any name you want. read the file out of SQL
into an image ( bitmap) object and write that to the stream.
Nov 19 '05 #2
> I think your approach is wrong. You can write files directly to the
response stream ( and give them any name you want. read the file out of SQL into an image ( bitmap) object and write that to the stream.


Never used response streams but understand that you're suggesting. This
isn't a full screen image - it's a page containing information about a
person with an image control on the page. If you were mocking it up, you'd
have something like:

<asp:Image
id="Image1"
style="Z-INDEX: 100; LEFT: 704px; POSITION: absolute; TOP: 152px"
runat="server"
ImageUrl="Porky.jpg"
BorderStyle="Solid"
BorderWidth="1px"
BorderColor="#7F9DB9" Height="234px"
Width="234px">
</asp:Image>

The advantage of using a <IMG> tag (which is I assume what asp:Image ends up
as) is that if the user right-clicks, then can save-as using the original
file name.

I can't see how you can repeat this functionality using a response stream
which I think is basically an "on-the-fly" HTTP response sent back to the
browser. It's not stored anywhere except within the browser to render the
current page. It can't be linked to via a IMG SRC tag.

Cheers, Rob.
Nov 19 '05 #3
I'm thinking on my feet here but I'm sure you can write your file into the
midle of the html.

If you call a function from the HTML e.g.
<HTML>
<BODY>
<TABLE><TR><TD>
<% =MyFunction() %>
</TD></TR></TABLE>
</BODY>
</HTML>
then in the code behind

public void MyFunction()
{
Response.Write("<IMG") ....
}
Nov 19 '05 #4
Rob Nicholson wrote:
I think your approach is wrong. You can write files directly to the
response stream ( and give them any name you want. read the file
out of SQL into an image ( bitmap) object and write that to the
stream.


Never used response streams but understand that you're suggesting.
This isn't a full screen image - it's a page containing information
about a person with an image control on the page. If you were mocking
it up, you'd have something like:

<asp:Image
id="Image1"
style="Z-INDEX: 100; LEFT: 704px; POSITION: absolute; TOP: 152px"
runat="server"
ImageUrl="Porky.jpg"
BorderStyle="Solid"
BorderWidth="1px"
BorderColor="#7F9DB9" Height="234px"
Width="234px">
</asp:Image>

The advantage of using a <IMG> tag (which is I assume what asp:Image
ends up as) is that if the user right-clicks, then can save-as using
the original file name.

I can't see how you can repeat this functionality using a response
stream which I think is basically an "on-the-fly" HTTP response sent
back to the browser. It's not stored anywhere except within the
browser to render the current page. It can't be linked to via a IMG
SRC tag.

Cheers, Rob.


An html-page with one image gives two requests to the browser: html-file
and image. (so you can't send the image along with the page)

Write the img-tag with an "src" pointing to some "getImage.aspx" (with appropriate
arguments to get the correct image).
In that getImage.aspx you read the image from the database and write it
(with Response.BinaryWrite) to the output (by the way: make sure the "aspx"
part contains no html code!).
But just before you do that, add some http headers:
Response.AppendHeader("Content-Disposition", "inline; filename=myfile.jpg");
Response.ContentType = "image/jpg";

When the user wants to save the image, he doesn't get "getImage.aspx", but
"myfile.jpg" as default filename. (of course: change that name to what you want)

No need for temporary files!

One thing you could change: when you retrieve the data for the page (including
the image), store that in Session. Then getImage.aspx doesn't need parameters,
it can just read the stored image.
Hans Kesting

Nov 19 '05 #5
Thanks for all your informative inputs.

Hi Rob,

As other members as mentioned, the <img src=... /> infact cause an
additional request to server to request the image. Generally this is a
static image file on the server. However, when the images we want to
display is to be retrieved from database, using static images files will be
abit hard since it need IO operations in our web application. Also,
creating those temporary files will need constant cleanup task , otherwise
there'll cause duplicated unuse files in the temp folder.

So in addition to your current solution, I think we can consider using a
HttpHandler to dynamically retrieve image and writeout as Image response
stream so that our <img src=../> tag can reference it. For example, our
aspx page which display image will become something like:

....
<img src="imagehandler.axd?param1=xxx&param2=xxx" />

Here is a good tech article discussing building such an httphandler:

#Using ASP.NET HTTP Handlers to create a photo album
http://www.microsoft.com/belux/nl/ms...et/httphandler.
mspx

Hope also helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 19 '05 #6
Hi Rob,

Any further progress on this? Have you chosen a certain means for exposing
your image streams from db? Anyway, if there are still anything we can
help, please feel free to let us know. Thanks,

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 19 '05 #7

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

Similar topics

6
by: Codemonkey | last post by:
Hi, I have a few questions about best practices when it comes to the management of temporary files. Any thoughts anyone can give would be much appreciated. Basically, I'm writing a document...
1
by: Frank Lopez | last post by:
In .NET and C#, is there anyway to create a hook for a specific directory or file where my C# .NET software can monitor which static web files are requested by the browser? What I am doing is...
2
by: Kiko + | last post by:
Hi, I've been getting this error: Server Error in '/applicationname' Application. ---------------------------------------------------------------------------- ---- Failed to create...
12
by: Chad Crowder | last post by:
Hi all, I hope someone can give me a hand, because I'm out of ideas. I keep getting this message: Access to the path "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET...
7
by: Norton | last post by:
Hi all, I would like to know if there is any method in asp or asp.net to direct the browser to download a file into the Temporary Internet Files directory so that i can make use of vb script to...
4
by: Nicolás Castagnet | last post by:
Hi, I write this post because I notice a strange behavior related with "Temporary Internet Files" and maybe some of you can help me to understand it. I am working in a web application with...
1
by: Manish | last post by:
Hi all, Can any one plz suggest me how i can delete my temporary internet files within my Asp.net page. I am using C# as the code behind lang. Indeed, i have flash inserted on my .net page,...
4
by: Anbu | last post by:
Hi all, I have developed an application in VS .NET 2003 (framework 1.1) on a XP platform. It is working fine in that PC. Now, I setup new PC with same configuration for another develper....
5
by: rogersw8n | last post by:
Some how, some way the account that creates folders under Temporary Internet files has been changed to a domain account for VS 2003 and VS 2005. I recently installed VS 2005. All seemed to be ok...
0
by: wolfsbane | last post by:
Alright, here it is I am trying to write a win32 app in VB 2005 to clean up user's profiles. everything works correctly except for the Delete("directory", True) statement. I get a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.