Request.IsAuthenticated is always true. What am I missing?

I try to add the username to the cookie and clear it when I log out, but it Request.IsAuthenticatedalways returns true, so I can’t find out if it is a member or not on the next page.

Here is what I am trying:

 public void Logout()
    {
        FormsAuthentication.SignOut();
        Session.Abandon(); // trying everything...
    }



protected void signin_submit_Click(object sender, EventArgs e)
    {
        //checklogins...
        HttpCookie authCookie = FormsAuthentication.GetAuthCookie(username_top.Text, true);
    }

I click the "Exit javascript function" button and it gets into the debugger, so I'm sure that it was called.

I check the value for Page_Load:

protected void Page_Load(object sender, EventArgs e)
    {
        bool isAuth = Request.IsAuthenticated; // always true !!!
        if (isAuth)
        {
            registeredDiv.Visible = true;
            guestDiv.Visible = false;
        }
    }

What am I missing? How do I know if a user is logged in or not?

Edit: I found out what is authenticationModeinstalled on Windows in web.config.

Edited as follows:

<authentication mode="Forms">

But now it always returns false. I tried redirecting after entering the same page, but still did not work. Any ideas?

+3
1

, Javascript, ajax? , , , , cookie, , /, , , , cookie - .

, , cookie ( ) ... MSDN RedirectToLoginPage(), cookie, .

FireCookie Firebug, .

Edit
MSDN, :

SignOut RedirectToLoginPage .

RedirectToLoginPage, FormsAuthentication.SignOut() ( RedirectToLoginPage)

2
, :

FormsAuthentication.RedirectFromLoginPage(username_top.Text, true)

cookie...

3
, . (edit 2) , , ( cookie )...

+7

Source: https://habr.com/ru/post/1791365/


All Articles