asp.net-core – MVC 6 OpenIdConnect
我目前遇到了将MVC应用程序从beta 3迁移到4的多个问题 – 其中一个问题与OpenIdConnect到
Windows Azure进行身份验证有关.当我转到具有“授权”属性的页面时,页面将停止处理并位于空白页面,而不会显示Azure登录页面.我没有得到YSOD – 只是空白屏幕.至于示例代码,我只能找到这些:
https://github.com/aspnet/Security/blob/5cf0564484cf5bb2a7a16e6485816d19287538e6/samples/OpenIdConnectSample/Startup.cs https://github.com/aspnet-contrib/AspNet.Security.OpenIdConnect.Server/blob/vNext/samples/Mvc/Mvc.Client/Startup.cs 如果我使用第二个示例,并且实际在不同的控制器中使用ChallengeResult,它确实会打开Azure登录页面,但会在Azure端返回错误请求(400). 这是我目前的代码: public void ConfigureServices(IServiceCollection services) { // Cannot find services.AddAuthentication that is supposed to be in Microsoft.Framework.DependencyInjection services.AddWebEncoders(); services.AddDataProtection(); services.Configure<ExternalAuthenticationOptions>(options => { options.SignInScheme = CookieAuthenticationDefaults.AuthenticationType; }); // Add MVC services to the services container. services.AddMvc(); } public void Configure(IApplicationBuilder app,IHostingEnvironment env,ILoggerFactory loggerfactory) { // Configure the OWIN Pipeline to use OpenID Connect Authentication app.UseCookieAuthentication(options => { options.AutomaticAuthentication = true; }); app.USEOpenIdConnectAuthentication(options => { options.ClientId = Constants.ClientId; options.Authority = Constants.Authority; options.PostLogoutRedirectUri = Constants.PostLogoutRedirectUri; options.TokenValidationParameters.RoleClaimType = "roles"; options.Notifications = new OpenIdConnectAuthenticationNotifications() { AuthorizationCodeReceived = async (context) => { var code = context.Code; ClientCredential credential = new ClientCredential(Constants.ClientId,Constants.AppKey); AuthenticationContext authContext = new AuthenticationContext(Constants.Authority,false); var result = await authContext.AcquireTokenByAuthorizationCodeAsync( code,new Uri(Constants.PostLogoutRedirectUri),credential,Constants.GraphUri); ActiveDirectoryHelper.token = result.AccessToken; } }; }); // More MVC stuff such as routing and static files } 附:有没有人为MVC 6提供任何有用的资源?我一直在为GitHub搜索我的大部分Beta 4代码. 解决方法
你遇到的问题与Cookie标题有关,如果你得到的400错误是“HTTP错误400.请求标题的大小太长了”,它超出了HTTP.sys的限制. Azure AD Cookie标头可能超出单个标头的限制.我有同样的问题,这是我的饼干:
您可能会看到类似的图片.有几种解决方法: >如果您可以控制服务器,请应用these registry changes以突破限制并重新启动服务器. app.UseCookieAuthentication(options => { options.AutomaticAuthentication = true; options.SessionStore = new MemoryCacheSessionStore(); });
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net-mvc-3 – 防止篡改ASP.NET MVC EF中的表单字段
- asp.net – 为什么DotNetNuke禁用了验证?
- asp.net-mvc – 会话超时处理的会话开始和操作过滤器
- asp.net网站 – 自动添加版本号?
- asp.net-mvc – ASP.NET MVC文件名下划线
- asp.net-mvc – Asp.net mvc 4部署错误
- asp.net-MVC – ASP.NET MVC:我可以说[授权角色=“管理员”
- asp.net-mvc – 如何从ASP.NET MVC VIEWS文件夹访问HTML文件
- asp.net – “填充无效,不能删除”异常WebResource.axd
- asp.net-mvc – 使用Viewbag绑定DropdownlistFor