18

When using the app_offline.htm feature of ASP.NET, it only allows html, but no images. Is there a way to get images to display without having to point them to a different url on another site?

Joshua Turner
  • 1,029
  • 2
  • 10
  • 16

6 Answers6

13

Yes, it just can't come from the site that has the app_offline.htm file. The image would have to be hosted elsewhere.

Ryan Farley
  • 11,315
  • 4
  • 46
  • 43
  • 4
    I don't see how this answers the question, since it clearly says: without having to point them to a different url on another site – sboisse Oct 02 '12 at 18:12
  • @sboisse When using an app_offline.htm with IIS you DON'T have to redirect to another URL at all. You change NOTHING, just drop in the htm file. IIS does the rest. Yes, technically, IIS is doing a redirect, however, my answer does correctly answer this since the question asked "without having to point them to a different url on a different site". This does NOT point them anywhere, not a different URL or site. As far as we're concerned the htm file just shows instead of the requested page. – Ryan Farley Oct 16 '12 at 20:46
  • 2
    Yes, but then the images will not display since every request made to the site will return that htm file, including image requests. My understanding of the question is: Is there a way to be able to get the images to show up in app_offline.htm without having the images to be retrieved from another site, i.e. the very same site where app_offline.htm is placed. Your answer does not fulfill those 2 conditions. Or if I am missing something? – sboisse Oct 18 '12 at 00:06
  • To me @derigel suggests the answer that is the closest to what we are looking for, that is to create a subdomain website with ASP.NET disabled so that will allow image requests to still be processed even if app_offline.htm is in the way. – sboisse Oct 18 '12 at 00:21
  • The authors original question (before he later edited it) was "Is there a way to get images to display with ASP.NET and app_offline.htm?". So, with that being the original question, my answer was correct. You can use images in an app_offline.htm file, they just cannot be from the same site. – Ryan Farley Oct 18 '12 at 23:00
12

Another solution is to embed the image inside the app_offline.htm page using a data URI. There is wide support for this these days - see the following for full details - http://en.wikipedia.org/wiki/Data_URI_scheme

Alex
  • 2,815
  • 2
  • 24
  • 22
5

If you don't support browsers prior to IE 8, you can always embed the images using a data URI.

http://css-tricks.com/data-uris/

Oran D. Lord
  • 697
  • 1
  • 9
  • 23
3

If you're willing to do a little more work you can easily create a custom page to take the application offline.

One possible solution:

  • Create DisplayOfflineMessage.aspx: Contains label to display your offline message from Application["OfflineMessage"].
  • ManageOfflineStatus.aspx: Contains an offline/online checkbox, textarea for offline message and an update button. The update button sets two application level variables, one for the message and a flag that states if the application is online. (This page should only be accessible to admins)

Then in Global.asax

 public void Application_Start(object sender, EventArgs e)
 {
     Application["OfflineMessage"] = "This website is offline.";
     Application["IsOffline"] = false;
 }



 public void Application_OnBeginRequest(object sender, EventArgs e)
 {
     bool offline = Convert.ToBoolean(Application["IsOffline"]);

     if (offline) 
     {

         // TODO: allow access to DisplayOfflineMessage.aspx and ManageOfflineStatus.aspx

         // redirct requests to all other pages
         Response.Redirect("~/DisplayOfflineMessage.aspx");
     }
 }
McGarnagle
  • 101,349
  • 31
  • 229
  • 260
Ryan Sampson
  • 6,717
  • 12
  • 47
  • 55
2

I have an idea.

You can create separate application, pointed to the same folder, without ASP.NET enabled. Then accessing to images by this application will not be affected by app_offline.htm file. Or, point that application direсtly to folder with static content, there will not be any app_offline files.

But, of course, you need to assign separate dns name for this application, kind of static.somedomain.com.

derigel
  • 3,218
  • 2
  • 19
  • 31
0

You could just convert your images to base64 and then display them:

    <html>
        <body>
            <h1>
                Web under maintenance with image in base64
            </h1>
            <img src="data:image/png;base64,iVBORw0K...=">
        </body>
    </html>

I've created a Fiddle where you can see it in action

Mario Levrero
  • 3,345
  • 4
  • 26
  • 57