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>
オフライン機能は機能しますが、主な問題は、ユーザーがオンライン モードでログオンしたときに、何も起こらなかったように見えることです。ページを少なくとも 1 回更新する必要があります。ユーザーがログインしたことがわかります。非常に面倒です。
アプリがオンライン モードでオフライン アプリケーション キャッシュを使用しないという解決策はありますか?