Tempdata,会话,Cookie对于作为子站点托管的.Net核心应用程序不起作用

问题描述

我正在使用.Net core 2.1,并且该网站托管在Windows服务器2016“ mywebsite.com/subsite”中的IIS中。 我正在尝试使用Ajax创建文件,成功后我试图使用放置在Tempdata / Session / cookie中的文件名下载文件(我尝试了全部三个)。

但是,当我在系统中本地运行应用程序(子站点)作为单独的解决方案时,一切运行正常。但是,当我在WS 2016中将应用程序发布到IIS时,tempdata / Session / Cookie始终返回null。我尝试如下所述在StartUp.cs文件添加所有可能的配置。

public void ConfigureServices(IServiceCollection services)
    {
        services.Configure<CookieTempDataProviderOptions>(options => {
            options.Cookie.IsEssential = true;
        });
        services.Configure<CookiePolicyOptions>(options =>
        {
            // This lambda determines whether user consent for non-essential cookies is needed for a given request.
            options.CheckConsentNeeded = context => false;
            options.MinimumSameSitePolicy = SameSiteMode.None;
        });
        services.ConfigureApplicationCookie(options =>
        {
            options.Cookie.SameSite = SameSiteMode.None;
        });


        //services.AddMemoryCache();
        //services.AddSession();
        services.AdddistributedMemoryCache();

        services.AddSession(options =>
        {
            // Set a short timeout for easy testing.
            options.IdleTimeout = TimeSpan.FromHours(1);
            options.Cookie.HttpOnly = true;
            // Make the session cookie essential
            options.Cookie.IsEssential = true;
        });
        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1).AddJsonoptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver()); 
        // Add Kendo UI services to the services container
        services.AddKendo();
        services.AddDbContext<DBContext>(options => options.UsesqlServer(Configuration.GetConnectionString("myConnection")));
        services.AddScoped<IRepository,Repository>();
        services.AddSingleton<IHttpContextAccessor,HttpContextAccessor>();
        services.AddSingleton<ITempDataProvider,CookieTempDataProvider>();
        
    }

    // 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("/Home/Error");
            app.UseHsts();
        }

        app.UseHttpsRedirection();
        app.UseStaticFiles();
        app.UseCookiePolicy();
        app.UseSession();
        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",template: "{controller=Home}/{action=Index}/{id?}");
        });
    }`

任何帮助将不胜感激`

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)