私はちょうどASP.NET MVCプロジェクトにスローされ、データベースのフラグがtrueに設定されているときに表示される「オフライン」ページを作成するように任されました。私は値をチェックし、それが本当であれば、私はサイト全体を任意の要求に対してオフラインにしたい。 ActionFilterを最後に作り、すべてのリクエストに追加しました。次に、ページが要求されると、Iはそれに応じてフィルタリングされます。しかし、これはオフラインページ自体もフィルタリングします。そのため、オフラインページかどうかを確認する行を作成しました。問題は、ログインページが次のように転送されていることです:/ Account/Login?ReturnUrl =%2FOffline、これはログインページの表示を終了します。この問題を解決するにはどうすればよいですか?ASP.NET MVC「オフライン」Page
public class DownForMaintenanceActionFilter : ActionFilterAttribute, IActionFilter
{
public DownForMaintenanceActionFilter()
{
}
void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext)
{
// If they are actually visiting the Offline page already, abort.
if (HttpContext.Current.Request.RawUrl.Contains("Offline"))
{
this.OnActionExecuting(filterContext);
return;
}
// We want to go to the "Down For Maintenance" Page if any of the following is true:
bool siteIsUp = true;
// Some other code here that sets siteIsUp = false
if (!siteIsUp)
RedirectToMaintenancePage(filterContext);
else
this.OnActionExecuting(filterContext);
}
private void RedirectToMaintenancePage(ActionExecutingContext filterContext)
{
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary
{
{ "controller", "Offline" },
{ "action", "Index" }
});
}
}
私は何をしたいのですか?これが最善のアプローチですか? また、サイトがでない場合に、このページにアクセスするのを防ぐにはどうすればよいですか?ありがとう!
ウェブサイトにapp_offline.htmを追加または削除するバッチファイルを作成する方が良いですか? – lordkain
何も知らないクライアントのために自動化する必要があります。 – skaz