willem
willem

Reputation: 27027

Where does the ASP.NET development server get its images from?

In my web application I dynamically generate images and want to show the images as part of a web page.

But, when debugging using the ASP.NET development server (not IIS) - I have no idea where to store these images so they can be referenced from my web application.

Should I use Directory.GetCurrentDirectory()?

Or Assembly.GetExecutingAssembly().Location?

Or Assembly.GetExecutingAssembly().CodeBase?

None of these paths seem to work.

Any ideas?

Upvotes: 0

Views: 237

Answers (4)

Muhammad Akhtar
Muhammad Akhtar

Reputation: 52241

Make a seprate aspx page, and put your code overthere that create your dynamic images.. your code should be look like....

        Response.ContentType = dtblProductImage[0].ImageFileExt;//image extension
        Response.BinaryWrite(dtblProductImage[0].ImageData); //your image binary


now go to that page where you want to show your image and set the image property of imageURL to your page, it will look like this....

<asp:Image ID="imgProduct" runat="server" ImageUrl="yourpage.aspx" />

Upvotes: 1

TheVillageIdiot
TheVillageIdiot

Reputation: 40527

You can write ashx handler to server images on the fly. Here is tutorial for this. It you want to generate and display them later then create a folder in your web-site folder tree and get its physical path using this:

  string imgPath = Server.MapPath("/") + "Images\" + IMAGENAME;

Upvotes: 1

fretje
fretje

Reputation: 8382

You can use

Server.MapPath()

Upvotes: 1

J&#248;rn Schou-Rode
J&#248;rn Schou-Rode

Reputation: 38356

Server.MapPath("~/") will give you the path the the root of the web application. Everything placed within the scope of this path should be automatically exposed by the web server, be it IIS or the VS devevelopment server.

The Server property is available in to all Page objects, and can otherwise be found on the HttpContext.

Upvotes: 3

Related Questions