第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

HttpContext.SignOutAsync() 既不注銷用戶也不刪除本地cookie

HttpContext.SignOutAsync() 既不注銷用戶也不刪除本地cookie

C#
吃雞游戲 2022-07-23 17:57:35
我知道已經(jīng)有關(guān)于這個主題的問題,但在我的情況下,給出的答案都沒有。這是核心:啟動.cspublic void ConfigureServices(IServiceCollection services)    {        services.AddDbContext<comedyContext>(options =>            options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));        services.Configure<CookiePolicyOptions>(options =>        {            // This lambda determines whether user consent for non-essential cookies is needed for a given request.            options.CheckConsentNeeded = context => true;            options.MinimumSameSitePolicy = SameSiteMode.None;        });        services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)            .AddCookie(options => {                options.LoginPath = "/login/";            });        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);    }    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.    public void Configure(IApplicationBuilder app, IHostingEnvironment env)    {        if (env.IsDevelopment())        {            app.UseDeveloperExceptionPage();        }        else        {            app.UseExceptionHandler("/Error");            // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.            app.UseHsts();        }        app.UseHttpsRedirection();        app.UseStaticFiles();        app.UseCookiePolicy();        app.UseAuthentication();        app.UseMvc();    }登錄.cshtml.cs    public class LoginModel : PageModel{    [BindProperty]    public string inputUsername { get; set; }    [BindProperty]    public string inputPassword { get; set; }    private readonly comedyContext _context;    public LoginModel(comedyContext context)    {        _context = context;    }
查看完整描述

2 回答

?
慕碼人2483693

TA貢獻(xiàn)1860條經(jīng)驗 獲得超9個贊

不完全是您所要求的,但也許這種方法會有所幫助。

我正在使用 Asp.Net Core 2.2 并在帳戶控制器中有以下 Logout() 方法。我使用身份服務(wù)并使用該路徑注銷而不是 HttpContext。對我來說,這個解決方案有效并刪除了登錄 cookie——至少在我?guī)追昼娗皺z查它時是這樣。

它與您的代碼的不同之處在于我使用的是 signInManager 對象而不是 HttpContext 對象,并且此 SignOutAsync() 不帶任何參數(shù)。

試試看,如果你喜歡,看看你會得到什么。請務(wù)必在您的 startup.cs ConfigureServices 方法中調(diào)用 AddIdentity() 或其變體。

http://img1.sycdn.imooc.com//62dbc63e0001354410650286.jpg

查看完整回答
反對 回復(fù) 2022-07-23
?
當(dāng)年話下

TA貢獻(xiàn)1890條經(jīng)驗 獲得超9個贊

對于您當(dāng)前的代碼,您將MVC Controller和合并Razor Page在同一個項目中,但您沒有為MVC Controller.


首先,檢查生成的 html 的Logout表單,確保它生成如下:


<form method="post" id="logoutForm" action="/Logout/Logout">

    <button type="submit">Logout</button>

<input name="__RequestVerificationToken" type="hidden" value="xxx"></form>

如果沒有,請配置您的 mvc 路由,例如


app.UseMvc(routes =>

{

    routes.MapRoute(

        name: "default",

        template: "{controller=Home}/{action=Index}/{id?}");

});

這是一個工作演示TestCookiesAuth


查看完整回答
反對 回復(fù) 2022-07-23
  • 2 回答
  • 0 關(guān)注
  • 600 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號