Is there a way to get images to display with ASP.NET and app_offline.htm?
Question
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?
Solution
Yes, it just can't come from the site that has the app_offline.htm file. The image would have to be hosted elsewhere.
OTHER TIPS
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
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");
}
}
If you don't support browsers prior to IE 8, you can always embed the images using a data URI.
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.