我正在尝试构建一个具有 HTML5 离线可能性的基于 ASP.NET MVC3(使用剃刀语法)的 Web 应用程序,但不幸的是它不能正常工作。
我阅读了很多教程,从中我使用了一些东西。
首先,这是我的 _Layout.cshtml 的相关部分:
<html manifest="@Url.Content("~/offline.appcache")">
.
.
@{
if(Request.IsAuthenticated)
{
@Html.ActionLink("Profile", "Profile", "Accounts", null, new { id = "profile" })
@Html.ActionLink("Logout", "Logout", "Accounts", null, new { id = "logout" })
}
else
{
@Html.ActionLink("Register", "Register", "Accounts", null, new { id = "register" })
@Html.ActionLink("Login", "Login", "Accounts", null, new { id = "login" })
}
}
.
.
@RenderBody()
其次,这是我的 CacheManifestHandler 类:
public class CacheManifestHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
//don't let the browser/proxies cache the manifest using traditional caching methods.
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.Cache.SetNoStore();
context.Response.Cache.SetExpires(DateTime.MinValue);
context.Response.ContentType = "text/cache-manifest";
context.Response.ContentEncoding = Encoding.UTF8;
context.Response.Write("CACHE MANIFEST" + Environment.NewLine);
context.Response.Write("CACHE:" + Environment.NewLine);
context.Response.Write("/Content/Main.css" + Environment.NewLine);
.
.
context.Response.Write("NETWORK:" + Environment.NewLine);
context.Response.Write("http://*" + Environment.NewLine);
context.Response.Write("*" + Environment.NewLine);
context.Response.Write("FALLBACK:" + Environment.NewLine);
context.Response.Write("/ /Error/PageNotAvailableOffline" + Environment.NewLine);
}
}
最后但同样重要的是,我将这些行放在了我的 web.config 文件中:
<handlers>
<remove name="CacheManifest" />
<add name="CacheManifest" verb="GET" path="offline.appcache" type="CMSP.Utilities.CacheManifestHandler" />
</handlers>
离线功能有效,但主要问题是当用户以在线模式登录时,似乎什么也没发生。我必须至少刷新一次页面,然后才能看到用户登录。这很烦人。
是否有任何可能的解决方案,应用程序在在线模式下不使用离线应用程序缓存?