D
D
da_normalny_ya2021-08-06 15:47:46
ASP.NET
da_normalny_ya, 2021-08-06 15:47:46

Why is controller method execution skipped in ASP.NET Core?

There is a master page with the following section responsible for the user's card (the ability to log in or go to the profile / log out of the account)

The code

<div class="header_form">

            <a class="logo_hiden" href="/">
                <img src="~/img/logo.svg" alt="TRUprogram">
            </a>
            @if (Context.Session.Keys.Contains("user"))
            {
                <div class="lk_mini">

                    <div class="user">
                        
                        <a class="n" href="~/User/Profile">
                            @Context.Session.GetString("user")
                        </a>
                        <a class="v" href="~/User/Logout">Выйти</a>
                    </div>

                    <a href="~/User/Profile">
                        <img width="50px" src="@Context.Session.GetString("userAvatar")" alt="avatar">
                    </a>

                </div>
            }
            else
            {
                <a href="~/User/Login"><input class="log_btn" type="button" value="Вход"></a>
            }
        </div>



the problem occurs when processing exit button click, here is the handler code:

The code

public IActionResult Logout()
        {
            if (!HttpContext.Session.Keys.Contains("user"))
                return LocalRedirectPermanent("/");

            foreach (var key in HttpContext.Session.Keys)
            {
                HttpContext.Session.Remove(key);
            }

            Response.Cookies.Delete(".AspNetCore.Session");
            return LocalRedirectPermanent("/");
        }


the essence of the problem is that this method is not called (checked through a breakpoint) and there is an immediate redirect (code 301) to the main page with the full path (/OtherPages/Index) , while sometimes the method is still called, but it is not possible to establish a pattern succeeded.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-08-06
@da_normalny_ya

The browser cached the 301 code and did not send the request.
Try clearing/clearing the cache or logging in incognito.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question