How can I make my imageurl control image dynamic depending on the host?

I am trying to convert my web application to a fully dynamic system. One thing I'm trying to do is load a different logo (set in the master page template) depending on the host.

But even though the code ended up (in page_init), on any page that inherits the master page, there is no image that has no image, no red x, nothing.

My code looks like this (from the main page, the image path is correct and pasted from the windows explorer properties window):

Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
    If Request.Url.Host.Contains("localhost") Then
        Image1.ImageUrl = "C:\Users\firstname.lastname\Documents\Visual Studio 2008\WebSites\ecardsystem\images\ECard Platform.jpg."


    End If

End Sub

      

I know that I can add an image on the fly using literal controls via codebehind, but that would mean that I also need to design the html by hand when the design is done and perfect. So this approach will create a little more work.

thank

0


source to share


2 answers


Have you tried using a virtual image path relative to your website? Internet Explorer usually does not display images from users' local file system with default security settings. Try putting an image in an image directory in your project and setting a URL for it relative to it:



Image1.ImageUrl = "~/images/Card Platform.jpg."

      

+1


source


The problem is ~ / images / Card Platform.jpg. is converted to say c: .SiteFolder \ images \ card

He finds the image on the local server, but when this page goes to the client ... some user xyz opened the same page ... the file was not found in his machine..and the path..c: .SiteFolder \ images \ map



Fixed we have to specify the image path relative to the site name: for example http: // localhost: 88 / images / card something like this ....

+1


source







All Articles