By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,005 Members | 1,226 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,005 IT Pros & Developers. It's quick & easy.

Show photo on ASP

P: n/a
I have an .NET ASP web application to show a photo depending on the person
selected. I used the url tag pointing to a file local to the server. All
works fine when running from the IDE. Problem: when I deploy it, I got a
permission error when creating the file. Question: where do I specify the
permission.
I am pretty new with web app, so any suggestion to alternate method is
welcome also.

Thanks.
Oct 4 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Phil,

This is most likely because on the server, ASP.NET is running under the
ASPNET local account, which doesn't have rights to the directory that you
specified. You have to either change the account that your application runs
under in the web.config file, or grant the ASPNET account permissions to
that directory.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Phil H" <ph*******@hotmail.comwrote in message
news:uZ**************@TK2MSFTNGP02.phx.gbl...
>I have an .NET ASP web application to show a photo depending on the person
selected. I used the url tag pointing to a file local to the server. All
works fine when running from the IDE. Problem: when I deploy it, I got a
permission error when creating the file. Question: where do I specify the
permission.
I am pretty new with web app, so any suggestion to alternate method is
welcome also.

Thanks.
Oct 4 '07 #2

P: n/a
I got a permission error when creating the file

Can you clarify; *showing* a photo sounds like a read operation, not a
write; are you writing the file into the local web? Generally, a
better option would be to simply stream it from source, perhaps using
a bespoke handler. You could also use virtual paths to bring the image
into the web itself.

Marc

Oct 4 '07 #3

P: n/a
I am reading the image from a database and writing into a file, No problem
there. I just cannot get the ImageURL to point to the right folder.

How do you stream the file into the web itself ? Where can I find out how ?

Thanks
"Marc Gravell" <ma**********@gmail.comwrote in message
news:11**********************@22g2000hsm.googlegro ups.com...
>I got a permission error when creating the file

Can you clarify; *showing* a photo sounds like a read operation, not a
write; are you writing the file into the local web? Generally, a
better option would be to simply stream it from source, perhaps using
a bespoke handler. You could also use virtual paths to bring the image
into the web itself.

Marc

Oct 4 '07 #4

P: n/a
I am reading the image from a database and writing into a file, No problem
there. I just cannot get the ImageURL to point to the right folder.

How do you stream the file into the web itself ? Where can I find out how ?
If I understand correctly, you simply don't need to write a file. What
I would do is in my page html (from aspx) page, refer to an image
(that doesn't exist) [see later], and then use a handler (e.g. ashx)
to serve the image. A handler is broadly just a fancy name for a class
that responds to requests, often much simpler than a full-blown aspx.
All it needs to do is:
* set the content-type so that the browser knows if it an image (and
what type)
* write the raw image to the response-stream

The latter is identical to working with a FileStream. The "handler"
step can be done in 2 ways; you can add a handler via the IDE and get
an .ashx file (with a query-string such as my.ashx?id=12345);
alternatively you can do the same without the actual ashx file, by
editing the httpHandlers section of web.config (you can then make the
URL look tidier, such as 12345.gif). Either way, the first thing your
handler has to do is to parse the URL to find which image to serve,
and fetch the binary.

A similar example: http://weblogs.asp.net/cazzu/archive.../27/25568.aspx
A good overview of handlers: http://msdn2.microsoft.com/en-us/library/ms972953.aspx

Marc

Oct 4 '07 #5

P: n/a
Thanks Marc.
It is a little over my head now. Let me see if if I can use the example and
learn somthing. Thanks for taking the time.

Phil
"Marc Gravell" <ma**********@gmail.comwrote in message
news:11**********************@r29g2000hsg.googlegr oups.com...
>I am reading the image from a database and writing into a file, No
problem
there. I just cannot get the ImageURL to point to the right folder.

How do you stream the file into the web itself ? Where can I find out how
?

If I understand correctly, you simply don't need to write a file. What
I would do is in my page html (from aspx) page, refer to an image
(that doesn't exist) [see later], and then use a handler (e.g. ashx)
to serve the image. A handler is broadly just a fancy name for a class
that responds to requests, often much simpler than a full-blown aspx.
All it needs to do is:
* set the content-type so that the browser knows if it an image (and
what type)
* write the raw image to the response-stream

The latter is identical to working with a FileStream. The "handler"
step can be done in 2 ways; you can add a handler via the IDE and get
an .ashx file (with a query-string such as my.ashx?id=12345);
alternatively you can do the same without the actual ashx file, by
editing the httpHandlers section of web.config (you can then make the
URL look tidier, such as 12345.gif). Either way, the first thing your
handler has to do is to parse the URL to find which image to serve,
and fetch the binary.

A similar example:
http://weblogs.asp.net/cazzu/archive.../27/25568.aspx
A good overview of handlers:
http://msdn2.microsoft.com/en-us/library/ms972953.aspx

Marc

Oct 5 '07 #6

P: n/a
Minor aside; the "read" steps would be tidier as follows:

while ((size = r.GetBytes(1, idx, buffer, 0, ChunkSize)) 0)
{
context.Response.BinaryWrite(buffer, 0, size);
idx += size;
}
(and remove the "last bytes" stuff)
This deals with a few edge-conditions more gracefully...

Oct 5 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.