I have created a simple MVC application that is using the .Net Membership Provider that is supplied with the new project.
I am trying to get the tabs to show correctly. I might not understand this right but here's my code:
<!DOCTYPE html>
<html>
<head>
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
</head>
<body>
<div class="page">
<div id="header">
<div id="title">
<h1>Suburban Customer Portal</h1>
</div>
<div id="logindisplay">
@Html.Partial("_LogOnPartial")
</div>
<div id="menucontainer">
<ul id="menu">
@if (Request.IsAuthenticated)
{
<li>@Html.ActionLink("ChangePassword", "ChangePassword", "Account")</li>
}else {
<li>@Html.ActionLink("Logon", "Logon", "Account")</li>
<li>@Html.ActionLink("Register", "Register", "Account")</li>
}
<li>@Html.ActionLink("ContactUs", "ContactUs", "Home")</li>
</ul>
</div>
</div>
<div id="main">
@RenderBody()
</div>
<div id="footer">
</div>
</div>
</body>
</html>
At this line:
@if (Request.IsAuthenticated)
I am trying to show the right tabs pending on if they are already authenticated. This is always coming out as true...
How should I be doing this? I apparently am not doing it the right way...
Thanks again!
I think you should use
@if(User.Identity.IsAuthenticated)
Well, your question is not very clear, but Request.IsAuthenticated in this line:
@if(Request.IsAuthenticated)
checks if the request has data about an authenticated user. If true, you link will be shown.
In your specific case the Change Password
link will only be shown if the user is logged in.
It looks correct.
For the tabs to be hidden, that is, for Request.IsAuthenticated = false
you must first logout
so that the cookies that store login information are cleared from the user browser.
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