Vasiliy Terkin
Vasiliy Terkin

Reputation: 165

How to check for logged-in user ASP in HTML?

I need to hide a link if a user is not logged in, and show the link if the user is logged in. I should use HTML. But the following:

 @if(Authorize(Roles = "admin")) <li>@Html.ActionLink(@Resources.LayoutLang.myarticles, "MyReviews", "Review")</li>

does not work. How to check the role in HTML?

Upvotes: 1

Views: 175

Answers (2)

peco
peco

Reputation: 4000

If you just want to check that the user is signed in:

@if (Request.IsAuthenticated)
{
    // do stuff
}

Upvotes: 1

Sirwan Afifi
Sirwan Afifi

Reputation: 10824

You can use IsInRole

  @if (User.IsInRole("admin"))
    {
         <li>@Html.ActionLink(@Resources.LayoutLang.myarticles, "MyReviews", "Review")</li>
    }
    else
    {
        <li>Not logged in</li>
    }

Upvotes: 0

Related Questions