我想在 asp.mvc core 3.X 中更改 .AspNetCore.Antiforgery.xxx 的默认 Cookie 名称,但是我似乎没有找到任何关于它的文档。甚至有可能吗?
我发现唯一可以改变的是:
services.Configure<CookiePolicyOptions>(options =>
{
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = Microsoft.AspNetCore.Http.SameSiteMode.Strict;
options.ConsentCookie.Name = "GDRP";
});
Run Code Online (Sandbox Code Playgroud) 我有
NuGet Microsoft.AspNetCore.Http.Abstractions
NuGet Microsoft.AspNetCore.Routing
Run Code Online (Sandbox Code Playgroud)
并使用命名空间
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
Run Code Online (Sandbox Code Playgroud)
我想构建这样的东西,但它似乎不知道 IEndpointConventionBuilder 也不知道 IEndpointRouteBuilder 并且拒绝编译。
public static class EndpointRouteBuilderExtensions
{
public static IEndpointConventionBuilder MapServiceEndpoints(this IEndpointRouteBuilder endpoints)
{
//some code
}
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么......?
System.ArgumentNullException: '值不能为空。(参数'connectionString')
我收到此错误我认为该问题来自 appsetting.json 但我找不到它
"AllowedHosts": "*",
"ConnectionString": {
"EmployeeDbConnection" : "server=(localdb)\\MSSQLLocalDB;database=EmployeeDB;Trusted_Connection=true;"
}
Run Code Online (Sandbox Code Playgroud)
错误来自 _config.GetConnectionString("EmployeeDbConnection)
public Startup(IConfiguration config)
{
_config = config;
}
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContextPool<AppDbContext>(options => options.UseSqlServer(_config.GetConnectionString("EmployeeDbConnection")));
services.AddScoped<IEmployeeRepository, SqlServerRepository>();
services.AddMvc(options => options.EnableEndpointRouting = false).AddXmlSerializerFormatters();
}
Run Code Online (Sandbox Code Playgroud)