I'm wondering why for one of my views I get the error "Section not defined: "featured2"". The path to the layout is correct, and I define the featured2 section in the view.

View

@using System.Data;
@using System.Data.SqlClient;
@{
ViewBag.Title = "Attempted Unauthorized Access";
Layout = "../Shared/Layout2.cshtml";
string whoareyoupeople = User.Identity.Name.ToString();
DateTime date = DateTime.Now;
string myerrorstring = "User " + whoareyoupeople + " attempted unauthorized access on " + date + ".";

    string fileName = "C:\\BillingExport\\SECURITY\\seclog.txt";
    using (FileStream fs = new FileStream(fileName, FileMode.Append, FileAccess.Write)){
    using (StreamWriter sw = new StreamWriter(fs))
    {
        sw.WriteLine(myerrorstring);
    }
}
}
@section featured2 {
<body>
    <head></head>
<center><h2 style="color:red">Access Denied for user @User.Identity.Name. You are not authorized to view this application.</h2></center>
    </body>
}

Layout2

@{
ViewBag.Title = "Layout2";
}

<link runat="server" rel="icon" href="../Content/images/eifavicon.ico" type="image/x-icon" />
@RenderSection("featured2")
@Scripts.Render("~/bundles/jquery")
@RenderSection("scripts", required: false)
                <script>
                                         browsername = navigator.appName;
                                         if (browsername.indexOf("Microsoft") != -1) {
                                             browsername = "MSIE";
                                             document.write("<p id='indent2'>You're viewing this page using Internet Explorer. Please use a supported browser (<a href='https://www.google.com/chrome/browser/'>Chrome</a>, <a href='https://www.mozilla.org/en-US/firefox/new/'>Firefox</a>)</p>");
                                         }

</script>

Related posts

Recent Viewed