C# .net core 2.2项目上的大量内存消耗。如何降低内存使用率?

C# .net core 2.2项目上的大量内存消耗。如何降低内存使用率?,c#,.net,asp.net-core,cookies,asp.net-identity,C#,.net,Asp.net Core,Cookies,Asp.net Identity,更新:似乎IIS正在重新启动,因为正在使用的应用程序池的最大内存(1024mb) 通过一些搜索,它在.NET2.0-2.2中是一个bug,但在3.0中应该改进很多 我尝试在CSProj文件中将服务器垃圾收集设置为false,这大大提高了登录时间 有没有其他方法可以改善记忆丧失 我有一个基于.NETCore2.2使用的标准身份的登录系统的网站。Startet可以正常工作,但最近它在1分钟后开始断开用户连接,无论他们是空闲的还是正在做一些活动的。然后,用户必须再次输入凭据才能返回 我尝试添加Coo

更新:似乎IIS正在重新启动,因为正在使用的应用程序池的最大内存(1024mb)

通过一些搜索,它在.NET2.0-2.2中是一个bug,但在3.0中应该改进很多

我尝试在CSProj文件中将服务器垃圾收集设置为false,这大大提高了登录时间

有没有其他方法可以改善记忆丧失


我有一个基于.NETCore2.2使用的标准身份的登录系统的网站。Startet可以正常工作,但最近它在1分钟后开始断开用户连接,无论他们是空闲的还是正在做一些活动的。然后,用户必须再次输入凭据才能返回

我尝试添加Cookie expirement,将expire设置为所有类型的值。我甚至尝试将滑动过期设置为真。这没什么区别。可能是因为我不了解身份验证是如何工作的。 这是我的startup.cs

    public void ConfigureServices(IServiceCollection services)
    {
        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.AddDbContext<ApplicationDbContext>(options =>
            options.UseSqlServer(
                Configuration.GetConnectionString("DefaultConnection")));
        services.AddDefaultIdentity<ApplicationUser>().AddEntityFrameworkStores<ApplicationDbContext>();
        services.AddScoped<WebsiteJobs>();
        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

        services.Configure<IdentityOptions>(options =>
        {
            options.Password.RequireDigit = false;
            options.Password.RequiredLength = 6;
            options.Password.RequireLowercase = false;
            options.Password.RequireDigit = false;
            options.Password.RequireUppercase = false;
            options.Password.RequireNonAlphanumeric = false;
        });
        services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
    .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme,
    options =>
    {
        //REF:https://tahirnaushad.com/2017/09/08/asp-net-core-2-0-cookie-authentication/
        //Cookie Authentication Options

        //Login View
        options.LoginPath = "/Identity/Account/Login";
        //Logout Action
        options.LogoutPath = "/Identity/Account/Login";
        //Controls how much time the cookie will remain valid from the point it is created. 
        options.SlidingExpiration = true;
        //Ticket Expiration :represents the expiration of the ticket NOT the cookie that contains the ticket.
        //an expired cookie will be ignored even if it is passed to the server after the browser should have purged it.
        options.ExpireTimeSpan = TimeSpan.FromMinutes(30);
        //Cookie Expiration
        options.Cookie.Expiration = TimeSpan.FromMinutes(30);
        //override default name of cookie, which is .AspNetCore.Cookies
        options.Cookie.Name = "expirationLoginCookie";
        //cookie can be accessed from client side scripts
        options.Cookie.HttpOnly = false;


        //ReturnUrlParameter = "returnUrl"
    });
        services.AddSession();
        services.AddSingleton<ITempDataProvider, CookieTempDataProvider>();
        //services.AddTransient<UserAccess>();
        services.AddHangfire(x => x.UseSqlServerStorage(Configuration.GetConnectionString("DefaultConnection")));
        services.AddElmahIo(o =>
        {
            o.ApiKey = "0966aa5059844c5e9d7263e47b41bdd0";
            o.LogId = new Guid("ddb3359e-6fc4-4bdc-801b-7e8d4d68a76c");
        });

    }

    // 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.UseExceptionHandler("/Home/Error");
            //app.UseDeveloperExceptionPage();
            app.UseDatabaseErrorPage();

        }
        else
        {
            //app.UseDeveloperExceptionPage();
            app.UseExceptionHandler("/Home/Error");
            app.UseHsts();
            app.UseDatabaseErrorPage();
        }
        app.UseMiddleware<ErrorLoggingMiddleware>();
        app.UseSession();
        app.UseHttpsRedirection();
        app.UseElmahIo();
        app.UseStaticFiles();
        app.UseCookiePolicy();

        app.UseAuthentication();
        app.UseHangfireServer();
        app.UseHangfireDashboard("/WebMaster/WebsiteJobs", new DashboardOptions
        {
            Authorization = new[] { new HangfireAuthorizationFilter() }
        });


        app.UseMvc(routes =>
        {
            routes.MapRoute(name: "areaRoute",
               template: "{area:exists}/{controller=Home}/{action=Index}/{id?}");

            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });
    }
}
public void配置服务(IServiceCollection服务)
{
配置(选项=>
{
//此lambda确定给定请求是否需要非必要cookie的用户同意。
options.checkApprovered=context=>true;
options.MinimumSameSitePolicy=SameSiteMode.None;
});
services.AddDbContext(选项=>
options.UseSqlServer(
GetConnectionString(“DefaultConnection”);
services.AddDefaultIdentity().AddEntityFrameworkStores();
services.addScope();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
配置(选项=>
{
options.Password.RequireDigit=false;
options.Password.RequiredLength=6;
options.Password.RequireLowercase=false;
options.Password.RequireDigit=false;
options.Password.RequireUppercase=false;
options.Password.RequireNonAlphanumeric=false;
});
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme,
选项=>
{
//参考:https://tahirnaushad.com/2017/09/08/asp-net-core-2-0-cookie-authentication/
//Cookie身份验证选项
//登录视图
options.LoginPath=“/Identity/Account/Login”;
//注销操作
options.LogoutPath=“/Identity/Account/Login”;
//控制cookie从创建时起保持有效的时间。
options.SlidingExpiration=true;
//票证过期:表示票证过期,而不是包含票证的cookie。
//过期的cookie将被忽略,即使它是在浏览器应该清除它之后传递给服务器的。
options.ExpireTimeSpan=TimeSpan.FromMinutes(30);
//曲奇过期
options.Cookie.Expiration=TimeSpan.FromMinutes(30);
//覆盖cookie的默认名称,即.AspNetCore.Cookies
options.Cookie.Name=“expirationLoginCookie”;
//可以从客户端脚本访问cookie
options.Cookie.HttpOnly=false;
//ReturnUrlParameter=“returnUrl”
});
services.AddSession();
services.AddSingleton();
//services.AddTransient();
services.AddHangfire(x=>x.UseSqlServerStorage(Configuration.GetConnectionString(“DefaultConnection”));
服务。AddElmahIo(o=>
{
o、 ApiKey=“0966aa5059844c5e9d7263e47b41bdd0”;
o、 LogId=新Guid(“ddb3359e-6fc4-4bdc-801b-7E8D48A76C”);
});
}
//此方法由运行时调用。使用此方法配置HTTP请求管道。
公共无效配置(IApplicationBuilder应用程序,IHostingEnvironment环境)
{
if(env.IsDevelopment())
{
app.UseExceptionHandler(“/Home/Error”);
//app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
其他的
{
//app.UseDeveloperExceptionPage();
app.UseExceptionHandler(“/Home/Error”);
app.UseHsts();
app.UseDatabaseErrorPage();
}
app.UseMiddleware();
app.UseSession();
app.UseHttpsRedirection();
app.UseElmahIo();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseAuthentication();
app.UseHangfireServer();
app.UseHangfireDashboard(“/WebMaster/WebsiteJobs”),新的仪表板选项
{
Authorization=new[]{new HangfireAuthorizationFilter()}
});
app.UseMvc(路由=>
{
routes.MapRoute(名称:“areaRoute”,
模板:“{area:exists}/{controller=Home}/{action=Index}/{id?}”);
routes.MapRoute(
名称:“默认”,
模板:“{controller=Home}/{action=Index}/{id?}”);
});
}
}

}

重新检查部署,可能有什么原因导致应用程序重新启动,从而丢失会话information@SahaKPGhoshal我不知道怎么做。是否有任何地方可以记录这些信息或查找有关部署的信息?什么会导致应用程序重新启动?@SahaKPGhoshal-你的评论让我找到了正确的方向:-D结果是服务器重新启动问题:-D如果你愿意,你可以发布一个答案;-)很高兴听到您已解决此问题。请重新检查部署,可能是由于某些原因导致应用程序重新启动,从而丢失会话information@SahaKPGhoshal我不知道怎么做。是否有任何地方可以记录这些信息或查找有关部署的信息?什么会导致应用程序重新启动?@SahaKPGhoshal-你的评论让我找到了正确的方向:-D结果是服务器重新启动问题:-D如果你愿意,你可以发布一个答案;-)很高兴听到你这么说