Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. using [Authorize] mvc3

using [Authorize] mvc3

Scheduled Pinned Locked Moved .NET (Core and Framework)
questionhtmldatabase
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xnaLearner
    wrote on last edited by
    #1

    So at the top of my controllers i've added in [Authorize], So far so good only logged in users can access these pages (Person and Holiday) However the tabs in the homeController which navigate the users to these pages are still displayed...coming from the layout.cs

      *   @Html.ActionLink("Home", "Index", "Home")
            *   @Html.ActionLink("About", "About", "Home")
            *   @Html.ActionLink("Person", "Index", "Person")
            *   @Html.ActionLink("Holidays", "Index", "Holidays")
    

    How can I only get these tabs to display if a user is logged in. I have tried the approach of adding in a bool in the AccountController.cs

    else
    {
    loggedIn = true;
    return RedirectToAction("Index", "Home");
    }
    }
    else
    {
    loggedIn = false;
    ModelState.AddModelError("", "The user name or password provided is incorrect.");
    }

    but then how do I access this from the layout.cs? Is this the correct approach. Please advise. thanks

    L 1 Reply Last reply
    0
    • X xnaLearner

      So at the top of my controllers i've added in [Authorize], So far so good only logged in users can access these pages (Person and Holiday) However the tabs in the homeController which navigate the users to these pages are still displayed...coming from the layout.cs

        *   @Html.ActionLink("Home", "Index", "Home")
              *   @Html.ActionLink("About", "About", "Home")
              *   @Html.ActionLink("Person", "Index", "Person")
              *   @Html.ActionLink("Holidays", "Index", "Holidays")
      

      How can I only get these tabs to display if a user is logged in. I have tried the approach of adding in a bool in the AccountController.cs

      else
      {
      loggedIn = true;
      return RedirectToAction("Index", "Home");
      }
      }
      else
      {
      loggedIn = false;
      ModelState.AddModelError("", "The user name or password provided is incorrect.");
      }

      but then how do I access this from the layout.cs? Is this the correct approach. Please advise. thanks

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Don't you think this would be more appropriate in the ASP.NET forum?

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] They hate us for our freedom![^]

      X 1 Reply Last reply
      0
      • L Lost User

        Don't you think this would be more appropriate in the ASP.NET forum?

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] They hate us for our freedom![^]

        X Offline
        X Offline
        xnaLearner
        wrote on last edited by
        #3

        ok thanks

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups