とのトラブル...レイザービュー - 私はちょうど私が見に期待していないいくつかのエラーを得た部分
明確にするために、私はエラーで動作するコードとコードを紹介します:
これは、作業
_MainLayout.cshtml
<div id="content">
<h1>@Page.Title</h1>
@RenderSection("left", false)
@RenderBody()
</div>
Page.cshtml
@section left{
<p>Some text on left side</p>
}
<div>
Some content
</div>
この場合、すべて正常に動作しますが、@RenderSection("left", false)
を_MainLayout.cshtml
の中に削除した場合、例外が発生します。どのケースが必要ですか?ユーザーが認証されていない場合
@if (WebSecurity.IsAuthenticated) {
<h1>@Page.Title</h1>
@RenderSection("left", false)
@RenderBody()
} else {
<h1>You not logged in!</h1>
<p>To see this page, you have to login first.</p>
}
がPage.cshtmlこの場合
@section left{
<p>Some text on left side</p>
}
<div>
Some content
</div>
に、私はこの例外を持って
_MainLayout.cshtmlが動作していない
これ以下の例を参照してください:
説明:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
例外の詳細:System.Web.HttpException: Следующие разделы были определены, но не были обработаны для страницы макета "~/_MainLayout.cshtml": "left".
として翻訳することができます:Section was created but wasn't rendered for layout page "~/_MainLayout.cshtml": "left".
ソースエラー:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
スタックトレース:
を[HttpException (0x80004005): Следующие разделы были определены, но не были обработаны для страницы макета "~/_MainLayout.cshtml": "left".]
System.Web.WebPages.WebPageBase.VerifyRenderedBodyOrSections() +91298
System.Web.WebPages.WebPageBase.PopContext() +332
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +95
System.Web.WebPages.<>c__DisplayClass7.<RenderPageCore>b__6(TextWriter writer) +102
System.Web.WebPages.HelperResult.WriteTo(TextWriter writer) +12
System.Web.WebPages.WebPageBase.Write(HelperResult result) +67
System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body) +66
System.Web.WebPages.WebPageBase.PopContext() +262
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +95
System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContext context) +249
問題はどうしたらいいですか? アドバイスは貴重です!
これは面白いですが、私はMVCを使用していません。 (私はWebMatrixで遊んでいて、私の考えを実現しようとしています)なぜ各ページのセキュリティを処理するのが愚かなのですか...しかし、私はエラーページにリダイレクトしようとします。多分それはうまくいくでしょう。ありがとうございます;) – RAMe0
確かに、私はWebSecurityクラスを選んだはずです。私はWebMatrixで多くの経験を持っていませんが、私はRazorも同様の動作をすると想定しています。あなたはWebMatrixを少し超えて何かをしようとしているかもしれませんか? –
はい、あります。私はWebMatrixが私が期待していたものと一致しないと考えました。しかし、それはまだ非常に有用なものがあります。今私は 'Context.RedirectLocal'を使用しています。これはログインしていないときにユーザーをエラーページにリダイレクトしています。これはうまく動作します。 – RAMe0