Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5935675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:17:19+00:00 2026-05-22T15:17:19+00:00

I have a few links (login, logout, and register) in the _layout template, where

  • 0

I have a few links (login, logout, and register) in the _layout template, where the links are shown depending on whether the user is logged in. Like so:

if (User.Identity.IsAuthenticated)
{
    <span class="username">@User.Identity.Name</span>
    <span class="link">@Html.ActionLink("Logout", "Logout", "Account")</span>
}
else
{
    <span class="link">@Html.ActionLink("Login", "Login", "Account")</span>
    <span class="link">@Html.ActionLink("Register", "Register", "Account")</span>
}

Problem is that the logout link is still displayed the first time the user logs out of the system (I would expect that to be immediately replaced with the login, and register links) – that is until the page is refreshed, or the user moves to another page. Here is the logout action code:

public ActionResult Logout()
{
    FormsAuthentication.SignOut();
    Session.Abandon();

    return View();
}

I have gone through this link – http://mvcdev.com/differences-between-asp-net-razor-and-web-forms-view-engines/ – which explains the execution order of the Razor engine, but in my case it seems to be executing differently. Ideally I would expect the FormsAuthentication.SignOut() to execute before the User.Identity.IsAuthenticated in the _layout.

What am I doing wrong? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:17:20+00:00Added an answer on May 22, 2026 at 3:17 pm

    That’s normal, you need to redirect after logging out:

    public ActionResult Logout()
    {
        FormsAuthentication.SignOut();
        Session.Abandon();
    
        return RedirectToAction("Index");
    }
    

    The reason this happens is because when the client requested the Logout link he was still authenticated (he sent the authentication cookie along with the request). Then inside the controller action you are logging him out (FormsAuthentication.SignOut()) which does nothing more than mark the authentication cookie for removal on subsequent requests. Then you return a view, and inside this view of course the user is still authenticated as this view executes under the same request and the cookie is still present.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have few links to .mp4 video files like file1.mp4 file2.mp4 file3.mp4 I need
I have a page with a few links that are all like this: <a
I have a few links across the page with the purpose of going to
I have a div, containing text and a few links. I want to trigger
I have a master page which containing few CSS links and java scripts. <html
I have got few things to work e.g. Using - FB.login(function(response) { if (response.authResponse)
i have this few lines of code FilterCondition CustomerID = new FilterCondition(Customer_ID,cust.Customer_ID,FilterCondition.FilterOperator.Equals); List<FilterCondition> conditions
I have the first few lines of a text file fx.txt with the following
I have written a few lines of code in Python to see if I
I have DIV element which only has a few lines in and a background

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.