ASP. NET in the page design, if the master template is used, the path of the image will be the most feared, and images will always disappear in different depth references! Some controls also have the same problems. So I finally came up with a method.
For images, we can define a path in the background. The path format is "~ /Image/test.jpg "is then referenced at the front end.
Note: "~" It can only be used on the server.
For example:
Text. aspx. CS
Public String imgpath = "~ /Image/test.jpg ";
Text. aspx
<Asp: Image id = "image1" runat = "server" imageurl = '<% = imgpath %>'/>
If it is a div or another background:
We can create an app_themes folder under a directory, and put the CSS file we have written in it. The image is similar to the file.
You can load the CSS in different places in the future.
PS: I just want to add one more sentence when talking about the path. For the control, the path in CS is relative to the folder where the control is located, rather than the folder where the page using the control is located.
For example, control 1 has an image1.imageurl = "images/test.jpg" in the background, control 1 is in the "include" folder, and the page using this control is in the root directory, the path of the image is in include/images.test.jpg, but not in images.test.jpg.
Supplement: (Supplement content from "humble programmer" http://jy147154.bokee.com/view. B? Diaryid = 16134580)
The path of. asax is the same as the path of the file included in ASP. There are two words: Trouble.
. The ASPX page can reference asax in this way.
<% @ Register src = "~ /Usercontrols/xxx. ascx "tagname =" myuc "tagprefix =" uc1 "%>
~ /Indicates the virtual root path relative to the site.
For. asax internal slices, connections, etc:
For Web empty parts such as Hyperlink and image, the path settings are the same as the following:
<Asp: hyperlink navigatorurl = "~ /Yourfolder/yourpage. aspx "runat = server/>
If it is a static hmtl such as <A/> MARK:
Method 1:
Add runat = server to make it an empty HTML Server:
Method 2: absolute path of the Dynamic Process
/images/myimg.gif">
Remember ~ /It only works for the server empty parts of ASP. NET.
1. "<% = httpcontext. Current. Request. applicationpath %>/
2. httpcontext. Current. Request. url. getleftpart (uripartial. Authority)
3. runat = Server