如何更改ASP核心2 tempdata cookie名称的名称? [英] How do you change the name of the ASP core 2 tempdata cookie name?

查看:126
本文介绍了如何更改ASP核心2 tempdata cookie名称的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Cookie名称为.AspNetCore.Mvc.CookieTempDataProvider。我想更改cookie的名称,以便为网站服务的技术提供线索。



我尝试了什么:



我看这里:

The cookie name is ".AspNetCore.Mvc.CookieTempDataProvider". I would like to change the name of the cookie so that there are clues to the technology that is serving the website.

What I have tried:

I looked here:

public void ConfigureServices(IServiceCollection services)



但是一无所获。


But found nothing.

推荐答案

services.Configure<CookieTempDataProviderOptions>(options => options.Cookie.Name = "MyTempDataCookie");





将它放在您的ConfigureServices方法中。



Put this in your ConfigureServices method.


public class Startup
{

    public void ConfigureServices(IServiceCollection services)
    {
       services.AddSingleton<ITempDataProvider, Interfaces.CookieTempDataProvider>();
    }

}

public class CookieTempDataProvider : ITempDataProvider
{
    const string TempDataCookieKey = "MyCookieName";

    public IDictionary<string, object> LoadTempData(HttpContext context)
    {

    }

    public void SaveTempData(HttpContext context, IDictionary<string, object> values)
    {

    }

}


这篇关于如何更改ASP核心2 tempdata cookie名称的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆