Asp.net core mvc Asp.net核心MVC 2.1-授权设置-
我正在为我的项目创建一个标识页面,我在互联网上的razor页面中找到了一个例子,我设法在MVC核心中对其进行了调整并执行了它,但在启动级别它会阻塞Asp.net core mvc Asp.net核心MVC 2.1-授权设置-,asp.net-core-mvc,Asp.net Core Mvc,我正在为我的项目创建一个标识页面,我在互联网上的razor页面中找到了一个例子,我设法在MVC核心中对其进行了调整并执行了它,但在启动级别它会阻塞 services.AddAuthentication(options => { options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultAuthenticateScheme = Co
services.AddAuthentication(options =>
{
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
}).AddCookie(options =>
{
options.LoginPath = new PathString("/Login");
options.ExpireTimeSpan = TimeSpan.FromMinutes(5.0);
});
services.AddMvc().AddRazorPagesOptions(options =>
{
options.Conventions.AuthorizeFolder("/");
options.Conventions.AllowAnonymousToPage("Login");
});
我应该怎么做才能使它适应我的mvc核心。
谢谢您需要使用正确的页面名。如果您将登录页面直接添加到MVC项目的
页面
文件夹下,请使用/Login
services.AddMvc().AddRazorPagesOptions(options =>
{
options.Conventions.AuthorizeFolder("/");
options.Conventions.AllowAnonymousToPage("/Login");
});
更新:
在MVC中,您只需在索引操作上设置[Authorize]
属性,并使用
services.AddAuthentication(options =>
{
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
}).AddCookie(options =>
{
options.LoginPath = new PathString("/Account/Login");
options.ExpireTimeSpan = TimeSpan.FromMinutes(5.0);
});
services.AddMvc();
首先,我要感谢你的回答。我不想使用ragor页面,我的模式如下-Models:Admin(用户名,passeword)控制器:帐户->(登录,注销,…),主页(->(索引,…)-视图:帐户登录,主页索引,因此,我的目标是锁定视图主页,以强制用户通过我的视图帐户。