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 8
ERR_HTTP2_INADEQUATE_TRANSPORT_SECURITY when clean webapi template
MissingMethodException: Method not found Microsoft.EntityFrameworkCore.Metadata.Builders.IndexBuilder
Migrate Asp.Net Core 2.2 Integration Tests to 3.0 - The TestServer constructor was not called with a IWebHostBuilder so IWebHost is not available. hot 4
UseStaticFiles with StaticFileOptions/FileExtensionContentTypeProvider breaks server side Blazor hot 3
SignalR .NetCore 3.0-- HubConnectionBuilder' does not contain a definition for 'WithUrl' hot 3
HTTP Error 500.30 - ANCM In-Process Start Failure hot 3
CSS Isolation in Blazor Components hot 3
How to retrieve the HttpContext from Blazor server-side ? hot 3
Oauth2 authentication erroring with "The oauth state was missing or invalid." hot 3
Failed to gracefully shutdown application (IIS Hang) hot 3
This server does not support the IHttpRequestBodySizeFeature hot 2
BadHttpRequestException: Reading the request body timed out due to data arriving too slowly hot 2
HTTP Error 500.0 - ANCM In-Process Handler Load Failure hot 2
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 2
source:https://uonfu.com/
Github User Rank List