I have 2 question
-
How to get absolute Uri in asp.net.
For example: Input: “~/Files/” , Output:”www.sampleweb.com/Files/” -
What is the “go to root” command in url on the client side like
server side command “~/Files/”
For example:
File location
myAspProjectName/Files/aa.jpg
myAspProjectName/User/bb.aspx
into the bb.aspx
<asp:image ImageUrl="~/Files/aa.jpg" id="img1" runat="server"/>
this work fine. But
<img src="~/Files/aa.jpg" alt=""/>
don’t work
Like Mark B says there is no obvious syntactic shortcut for this.
If you’re doing it with the current request then you can just use
Request.Urlor for an arbitrary file you can usePage.ResolveURL("~/some/path")if you are using an ASP.Net page. These are methods that will generate absolute relative URIs i.e. those of the form /path/somefile then if you then get the host name using Mark B’s approach you can concatenate the two things together.As for (2) I think you possibly mean absolute relative URIs. If a relative URI begins with a forward slash it is resolved as being relative to the base domain e.g. if you were on the page
http://yourdomain.com/somedir/somepage.aspxand you followed a link which was/otherdir/somepage.aspxyou’d end up athttp://yourdomain.com/otherdir/somepage.aspx