I have an MVC 5 Site, using a shared _Layout view. In this _Layout view i render my scripts in the bottom part, after the body.
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
@*BootStrap must be loaded after JQuery UI in order to override the tooltip function*@
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/Session")
My Problem now, is that i want to include the Session Bundle in every page, except my Login pages. In other words, i want to use the Session Bundle only for pages where the user is logged in and they have an active session.
How can i check for this condition in my _Layout View and render the Script Render conditionally?
In other pages, i would add a bool field to my Model and then use an C# If construction to only render the Script part if true, but i do not have a Model in my _Layout View.
I am also using custom, very simple login methods, so i am not using the Identity Framework of MVC5.
EDIT I was suggested to use the Request object
@if (Request.IsAuthenticated) { @Render...}
This does not work since im using custom login, that does not work with the built in framework. I read up on how this field works, here How does Request.IsAuthenticated work?
The problem is still unresolved
@if (Request.IsAuthenticated)
{
// Render stuff for authenticated user
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With