c# - 身份服务器 4 在生产中注销时返回 404 错误是否有原因

标签 c# asp.net-core-2.0 identityserver4 iis-8 windows-server-2012

我目前在实现身份服务器 4 时遇到生产中的问题。

当我执行登录时,我会被重定向到身份服务器,并且我可以毫无问题地进行身份验证。

当我尝试注销时,我的问题出现了。我被重定向到“connect/endsession”端点上的身份服务器,并返回 404。

我什至尝试了所有浏览器,都是同样的问题。 生产:MS server 2012、iis 8 和 .net core 2.1

这里有一些代码示例:

在我的客户端启动中:

services.AddAuthentication(option => {
            option.DefaultScheme = "Cookies";
            option.DefaultChallengeScheme = "oidc";


        }).AddCookie("Cookies")
        .AddOpenIdConnect("oidc", options => {
            options.SignInScheme = "Cookies";
            options.Authority = Configuration["Authentication:Authority"]; // identity.example.com
            options.RequireHttpsMetadata = false;
            options.ClientId = Configuration["Authentication:ClientId"]; //example.mvc
            options.SaveTokens = true;
            options.GetClaimsFromUserInfoEndpoint = true;
            options.ClientSecret = Configuration["Authentication:ClientSecret"] //!@examplepassword@! ;

        });

在帐户 Controller 中我有这个注销方法

 public async Task Logout()
    {

        await HttpContext.SignOutAsync("Cookies");
        await HttpContext.SignOutAsync("oidc");


    }

在身份服务器中

我的客户端存储实现从 json 文件中提取客户端对象并正确映射它,我知道这可以工作。

{
  "Enable": true,
  "ClientId": "example.mvc",
  "ClientName": "example enterprise ",
  "RedirectUris": [ "http://www.example.com/signin-oidc" ],
  "PostLogoutRedirectUris": [ "http://www.example.com/signout-callback-oidc" ],
  "AllowAccessTokensViaBrowser": true,
  "RequireConsent": false,
  "ClientSecret": "!@examplepassword@!",
  "AllowedScopes": [ "openid", "profile", "email" ],
  "GrantType": "implicitandclientcredentials"
} 

当点击注销时,我希望永久注销。但由于某种原因我收到了 404 错误。

不确定我是否必须添加一个具有 [Route("/signout-callback-oidc")] 的 Controller ,但由于某种原因我无法让注销在生产中工作。

有趣的是,它可以在我的电脑上本地运行,我尝试调试它。

最佳答案

事实证明,这是iis中的最大url长度限制,当点击时,返回404。我修改了startup.cs文件中的.AddOpenIdConnect方法并添加到一行中。

.AddOpenIdConnect("oidc", options => {
            options.SignInScheme = "Cookies";
            options.Authority = Configuration["Authentication:Authority"];
            options.RequireHttpsMetadata = false;
            options.ClientId = Configuration["Authentication:ClientId"];
            options.SaveTokens = true;
            options.GetClaimsFromUserInfoEndpoint = true;
            options.ClientSecret = Configuration["Authentication:ClientSecret"];
            options.AuthenticationMethod = OpenIdConnectRedirectBehavior.FormPost; // adding this line fixed my problem. and i can now logout permanently. 

        });

关于c# - 身份服务器 4 在生产中注销时返回 404 错误是否有原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54256463/

相关文章:

c# - 将 TCP 客户端从 c# 转换为 nodejs

c# - 如何使用 open xml sdk 在 .xlsx 文件的现有行中添加新单元格?

c# - 如何获取 IdentityServer4 登录用户的列表?

c# - 我可以使用哪些方法来检测机器人?

c# - 如何在 TemplateField 中更改 ItemTemplate 的命令文本和 ImageButton

c# - StreamReader.ReadLine() 不消耗流

c# - 在响应 header 中传递非 ASCII 字符

c# - 为 ASP.NET Core 配置引用 appsettings.json 中的另一个 json 文件

asp.net-core - 为什么 ClaimTypes.NameIdentifier 没有映射到 'sub' ?

asp.net - 身份服务器 4 使用有效访问 token 获取 401 未授权