开发者

Convert physical path to web path asp.net

I need to display an Image in web page. But the Image doesn't exist in the Web directory. If the image is under web directory I know that just "../Images/TN/my.jpg" will work. But the image 开发者_运维知识库is available in "D:\Images\TN\my.jpg" and My web site is deployed in "C:\apps\mywebsite".

How do I convert the "D:\Images\TN\my.jpg" path to a relative path so that the Image will be visible in web page?


You cant show images if they are not in a virtual directory. Try holding then in your application folder itself or if its not feasible then make your Folder holding the image as a virtual directory in the IIS and mount it in your application folder.

Here's what you need to do (way i prefer),

  1. Open IIS manager.
  2. In Connections under Sites Select your Website and RightClick on it.
  3. Select `Add Virtual Directory`... from the Context menu.
  4. In The dialogue box that opens Enter the Alias name of your choice like **`"GlobalImages"`**
  5. Browse the physical path of the Folder you want to and Select it and Click OK.

You will have it available for relative url in that website. like

www.example.com/GlobalImages

When you set that in IIS, it is automatically added to your Solution's Project.

Here is the MSDN link if you want..

http://msdn.microsoft.com/en-us/library/ms751432.aspx


Easiest thing to do is probably set up a handler and use the generic image name. While local, point to the D:. While on the server, point to the web path. (At least so long as you're not keeping them within the virtual directory that is).


TO fetch this point, we always write the absolute directory for images or other resource.But if the resource in the web server, i use the relative directory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜