Is there a "symbol" in .NET that identifies a virtual path?

Let's assume this scenario. On mine, Default.aspx

I insert a context (WebForms) called MyContext.ascx

that loads the image. So the path will be as follows:

<img src="/images/hello.gif" />

      

Well. Now I would like to insert the same context into another .aspx page, i.e. in another forlder, for example/myfolder/MyPage.aspx

What the path to the image should now be:

<img src="../images/hello.gif" />

      

As you can see, I cannot manage two different paths for the same context. So, is there a way (symbol) to call virtual-path

my application? Without using my own function

<img src="<%=MyUtilities.GiveVirtualPath%>/images/hello.gif" />

      

which is boring. Who knows?

+3


source to share


1 answer


Place your images at the root of your website (and inside your resources / styles / themes folder). You can use a tilde ~

to indicate the root of your site. All of your pages will link to this. If you are using server side controls, you don't even need to use the method ResolvePath()

(in your example, you should use that if, for example, you wrote asp: image ImageUrl = "you don't need. From MSDN .



+2


source







All Articles