超时后进入白页

问题描述 投票:0回答:1

我有一个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。

任何人都可以提出相同的建议吗?谢谢

asp.net-mvc authentication asp.net-core authorization session-cookies
1个回答
0
投票

您可以在Cookie设置中配置拒绝访问的路径:

services.ConfigureApplicationCookie(options =>
{
    options.AccessDeniedPath = $"/Identity/Account/AccessDenied";
});

只需确保页面存在。

© www.soinside.com 2019 - 2024. All rights reserved.