Is there a way to get images to display with ASP.NET and app_offline.htm?

半世苍凉 提交于 2019-12-14 00:18:05

问题


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?


回答1:


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




回答2:


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




回答3:


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/




回答4:


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");
     }
 }



回答5:


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.



来源:https://stackoverflow.com/questions/32715/is-there-a-way-to-get-images-to-display-with-asp-net-and-app-offline-htm

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!