profile
viewpoint

Ask questionsWith Asp.net core 3.0 SignInManager.IsSignedIn(User) allways reuturn false?but in 2.2 it works fine.Is that a debug?

With Asp.net core 3.0 SignInManager.IsSignedIn(User) allways reuturn false?but in 2.2 it works fine.Is that a debug?

this is my code of SignIn

        [HttpPost]
        public async Task<IActionResult> Login(LoginViewModel model,string returnUrl=null)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }
            var user = await UserManager.FindByNameAsync(model.UserName);
            if (user!=null)
            {
                await SignInManager.SignOutAsync();
                var result = await SignInManager.PasswordSignInAsync(
                user, model.Password, model.RememberMe, true);
                if (result.Succeeded)
                {
                    //var userName = HttpContext.User.Identity.Name;
                    var userName = UserManager.GetUserName(HttpContext.User);
                    //return RedirectToAction("Index", "Note");
                    return Redirect("/");
                }
                else
                {
                    ModelState.AddModelError("", "用户名或密码错误");
                    return View(model);
                }
            }
            else
            {
                ModelState.AddModelError("", "用户名或密码错误");
                return View(model);
            }
            
        }


but SignInManager.IsSignedIn(User) allways return false.and HttpContext.User.Identity.Name return null?

@if (SignInManager.IsSignedIn(User))
{
    <form asp-controller="Account" asp-action="LogOff" method="post" id="logoutForm" class="navbar-right">
        <ul class="navbar-nav">
            <li>
                <a href="javascript:;">@UserManager.GetUserName(User)</a>
            </li>
            <li>
                <a href="javascript:document.getElementById('logoutForm').submit()">注销</a>
            </li>
        </ul>
    </form>
}

I tried to use scaffold to generate the Identity code. It works fine? but if i replace the razor page with in my project, it doesn't work. Could anybody help me?

aspnet/AspNetCore

Answer questions riyuexing

OK,Thank you.I got it. I am sorry, to bother you with this. May God bless you! May Gold bless AspNetCore!

------------------ 原始邮件 ------------------ 发件人: "Hao Kung"<notifications@github.com>; 发送时间: 2019年10月8日(星期二) 下午3:45 收件人: "aspnet/AspNetCore"<AspNetCore@noreply.github.com>; 抄送: "赵志刚"<1401527242@qq.com>;"Author"<author@noreply.github.com>; 主题: Re: [aspnet/AspNetCore] With Asp.net core 3.0 SignInManager.IsSignedIn(User) allways reuturn false?but in 2.2 it works fine.Is that a debug? (#14755)

You seem to be missing a UseAuthentication() which should go before UseAuthorization()

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

useful!

Related questions

HTTP Error 500.31 - ANCM Failed to Find Native Dependencies hot 123
The SPA default page middleware could not return the default page '/index.html' in production application hot 102
The SPA default page middleware could not return the default page '/index.html' in production application hot 96
Asp.Net MVC Core: “Error unprotecting the session cookie” exception hot 79
No DefaultChallengeScheme found from preview8 to preview9 hot 67
BadHttpRequestException: Reading the request body timed out due to data arriving too slowly hot 65
Method not found: 'Microsoft.EntityFrameworkCore.Metadata.Builders.IndexBuilder Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder`1.HasIndex(System.Linq.Expressions.Expression`1<System.Func`2<System.__Canon,System.Object>>)'. hot 59
The library &#39;hostpolicy.dll&#39; required to execute the application was not found - AspNetCore hot 58
error CS1503: Argument 2: cannot convert from 'method group' to 'EventCallback' hot 57
Error: Invocation canceled due to the underlying connection being closed. hot 54
Unexpected end of request content k8s pod - AspNetCore hot 53
Using 'UseMvc' to configure MVC is not supported while using Endpoint Routing. To continue using 'UseMvc', please set 'MvcOptions.EnableEndpointRounting = false' inside 'ConfigureServices'. hot 50
IIS in-process hosting incorrectly throws ConnectionResetException for HTTP POST hot 47
HTTP Error 500.30 - ANCM In-Process Start Failure hot 43
Error: Server returned handshake error: Handshake was canceled. hot 43
source:https://uonfu.com/
Github User Rank List