超时后为白页

时间:2019-10-03 15:52:51

标签: asp.net-mvc authentication asp.net-core authorization session-cookies

我有一个Web应用程序mvc,它使用asp.net核心mvc 2.2构建。

在工作时,一切正常。

当我放弃很多浏览器时,当我返回并单击链接或按F5时,页面将变为白色,而没有任何应用程序错误:仅401错误。

我复制此错误,删除“ .AspNetCore.Identity.Application” Cookie(会话到期)。

.AspNetCore.Identity.Application cookie默认是它。

在这里,我的创业班:

'c#

namespace MyWebApp
{
    public class Startup
    {

        private ApplicationDbContext _mycontext;



        public Startup(IHostingEnvironment env)
        {
           //something            
        }

        public IConfiguration Configuration { get; }


        public void ConfigureServices(IServiceCollection services)
        {
            int minutes = 10;   //to appsettings

            services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(
                Configuration.GetConnectionString("DefaultConnection"),
                sqlServerOptions => sqlServerOptions.CommandTimeout((60*minutes)+1))
                );


            services.AddIdentity<ApplicationUser, ApplicationRole>(options =>
            {
                options.Password.RequireDigit = false;
                options.Password.RequiredLength = 4;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase = false;
                options.Password.RequireLowercase = false;

            })
            .AddEntityFrameworkStores<ApplicationDbContext>()
            .AddDefaultTokenProviders();


            services.AddTransient<IEmailSender, EmailSender>();
            services.AddSingleton<IMvcControllerDiscovery, MvcControllerDiscovery>();

            services.AddMvc(options => options.Filters.Add(typeof(DynamicAuthorizationFilter)));    //mmmmmm

            services.AddHttpContextAccessor();

        }

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ApplicationDbContext context, RoleManager<ApplicationRole> roleManager, UserManager<ApplicationUser> userManager, ILoggerFactory loggerFactory)
        {


            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();
            loggerFactory.AddContext(LogLevel.Information, Configuration.GetConnectionString("DefaultConnection"));


            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            app.UseStaticFiles();



            app.Map("/fexml", subApp =>
            {
                //something   
            });

            app.Map("/fexml-d", subApp =>
            {
                //something   
            });


            DataSeed.Initialize(context, userManager, roleManager).Wait();

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

        }
    }
}

我点击了以下链接: https://www.codeproject.com/Articles/1248792/Dynamic-Role-Based-Authorization-in-ASP-NET-Core 来建立DynamicAuthorizationFilter。

任何建议都可以吗? 谢谢

0 个答案:

没有答案