Absolute url from relative path in an ascx file? - image

Imagine I have an image hosted at http://www.mypage.com/content/images/myimage.png and I want to display it on my webpage. In my ascx file is the following:
<img runat="server" id="ImgLarge" class="myimage" src="../content/images/myimage.png" />
The only problem is that this image doesn't print. I believe the fix is to have the image use the absolute URL but I'd rather not use http://www.mypage.com/content/images/myimage.png and instead use something like src=#Url.Absolute('~/images/solar-panel.png').
Does this work in ascx files? If not, is there an alternative? I've only ever done this in my cshtml files. Thanks!

Is the image a part of the project? Typically you would have your user controls in one folder and image controls in another (same level). If this is the case, you would have a url like this:
<asp:ImageButton runat="server" ID="ImageButton2" OnClick="sortApproved_Click" ImageUrl="~/images/down.png" />
Other wise, if you want to diagnose whats going on, look at the rendered web pages source. What does the url look like?

Related

Generate Pinterest Share Button That Specifies URL

I am trying to create a "pinterest share" button, but am running into a snag.
Currently, I have the pinterest button (generated from their Widget Builder) appearing in a Lightbox. (For certain reasons, it must appear this way.)
The issue is the Lightbox code has direct linking on it, so the code for the lightbox window is something like: www.domain.com/#/social/4
Pinterest is picking up that URL (which has no images since it's just the lightbox) instead of the URL for the main page (www.domain.com).
Does anyone know how I can specify the exact URL to share via the pinterest button?
I have read some posts that said doing this would work:
<img src="//assets.pinterest.com/images/PinExt.png" alt="Pin it" / > <script type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"></script>
However, specifying the URL does not seem to work at all. It appears to be totally ignored and has no impact.
Any ideas?
Thanks in advance!
You can use a standard link and specify all the data in the parameters:
<a href="http://www.pinterest.com/pin/create/button/
?url=http%3A%2F%2Fwww.flickr.com%2Fphotos%2Fkentbrew%2F6851755809%2F
&media=http%3A%2F%2Ffarm8.staticflickr.com%2F7027%2F6851755809_df5b2051c9_z.jpg
&description=Next%20stop%3A%20Pinterest"
data-pin-do="buttonPin"
data-pin-config="above">
<img src="//assets.pinterest.com/images/pidgets/pin_it_button.png" />
</a>
Source: http://developers.pinterest.com/pin_it/
You can try using structured meta data and Rich Pins.

IIS 7.5 hierarchy breaks application path

I've setup a web application under a website using information from IIS.Net - Understanding Site, Applications and Virtual Directories
Below is what they say regarding applications.
An application is a group of files that delivers content or provides services over protocols, such as HTTP. When you create an application in IIS, the application's path becomes part of the site's URL.
That's great; exactly what I want; however...the application path is not resolving properly for script files, css and a web service I have in the application.
For http://site_name/application_name
<img src="/Content/images/smiley.png" alt="smiley face" /></a>
resolves to
src="/site_name/Content/images/smiley.png"
instead of
src="/application_name/Content/images/smiley.png"
As a work-around I've wrapped the paths I was using withe #Url.Content() helper. Not the prettiest solution, but it's working.
<img src="#Url.Content("~/Content/images/smiley.png")" alt="smiley face" /></a>
Is there a way to fix this in IIS?
This is not an IIS issue, this is something you'd have to do on the template side. Now, I'm not sure, but in asp.net mvc4/razor 2 there might be some additional magic that allows you to instead of
<img src="#Url.Content("~/Content/images/smiley.png")" alt="smiley face" />
do
<img src="~/Content/images/smiley.png" alt="smiley face" />
and everything is converted automatically to the proper path. Actually this blog post seems to document that ability.
But but otherwise, <img src="/path/to/image.png" alt="smiley face" /> is always going to refer to http(s)://(current server)/path/to/image.png, unless, somehow the html is rewritten before it is seen in the browser.
Using #Url.Content is the right way here IMO. It then makes the links work regardless of how a developer is setup on their machine (running the dev server, or using IIS).
I'm not sure if there's a way to deal with it in IIS, maybe a URL rewrite rule, but it won't help with consistency across development machines.
Edit: You could deploy the site to the root of the site in IIS, as opposed to a virtual directory, but that is only a good solution if you're only going to be hosting this single site.
Add this "base" tag in your "head" section: <base href="~/" target="_blank" />. I was having the same problem with my anchor elements.

How do I use relative http urls for Xaml images

I have a need to treat an image in XAML as a special case and have it download the image using the relative HTTP URL and not the relative DLL path. But I cannot seem to get that to work properly. I've tried the pack URL, but it seems to ignore it. None of these appear to work.
<Image Source="pack://siteoforigin:,,,/images/logo.png" />
<Image Source="~/images/logo.png" />
<Image Source="/images/logo.png" />
I would simply like these to work like ordinary HTML img src. I know I can do this in code, but I'm hoping to avoid that if I can.
I finally found a way to get this to work. My xap file is loaded from /ClientBin/, so the resulting URLs for the download are actually this:
/ClientBin/images/logo.png.
Once I realized that was happening, I was able to add URL map to my web.config and an HttpHandler to redirect the image download where I need it to go.

Spring web development images

Can anybody tell me or give me a link to go to which can tell me how to implement and display images step by step (I'm only beginning) on a webpage from a spring project
I'm using IntelliJ
Thanks
What's the URL of the page? The one that appears in the location bar of your browser?
That is the URL to which relative locations are resolved in the HTML code. So, if the URL is http://localhost/MyApp/foo.html, and the URL of the CSS inside the HTML code is ../../css/style.css, the absolute URL where the browse will try to find the CSS will be http://localhost/MyApp/../../css/style.css, which doesn't make sense.
I prefer always using absolute paths for images and CSS files (and other resources). Using JSTL, that makes it like
<link href="<c:url value='/css/style.css'/>" ...
The <c:url> tag takes care of prepending the application context (/MyApp) to the path.
Note that relative paths inside CSS files are not resolved relative to the page URL, but relative to the location of the CSS file itself. So the path in your CSS file is correct.

where should I add external file to view in CI

I'm trying to make view page in CodeIgniter,So I create it and in Controller it loads complete.
but when I add images and jQuery to it,they will not be loaded.
I made sub folder in view folder by name of Files and add to view for e.g like that
img src="Files/01.jpg" but it will not be shown.
where should I place them?
I usually make a folder called files in the main directory (where system and application reside), and then link to them using base_url().
In your case, this would become
<img src="<?= base_url(); ?>/files/01.jpg" />
Hope that helps.
When your view loads, the file paths will be relative to the directory the CodeIgniter index.php file is located in. If this is also the root directory of your site, you can refer to it in this way: <img src="/Files/01.jpg" />

Resources