小编Fra*_*ser的帖子

如何修复“客户端身份验证方案‘匿名’禁止 HTTP 请求”

我在实现与 WCF 服务通信的客户端时遇到一些问题。它是由另一家公司托管的 WCF,因此我无权访问其代码。我使用 Visual Studio 中的连接服务提供程序工具生成客户端代码,以便我可以发出请求,并且一切都在我的本地计算机上正常运行。我的开发环境遇到问题,如果我尝试向客户端发出请求,则会收到以下错误:

The HTTP request was forbidden with client authentication scheme 'Anonymous'
Run Code Online (Sandbox Code Playgroud)

我一直在查看由提供程序工具生成的客户端代码(有很多代码),我认为它可能与以下代码块有关。

System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
result.MaxBufferSize = int.MaxValue;
result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
result.MaxReceivedMessageSize = int.MaxValue;
result.AllowCookies = true;
result.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport;
return result;
Run Code Online (Sandbox Code Playgroud)

.net c# wcf asp.net-core

8
推荐指数
2
解决办法
6万
查看次数

如何使 ASP.NET Core 中的身份验证 cookie 无效?

我在使 ASP.NET Core 3.0 中的身份验证 cookie 无效时遇到问题。

设想

我有一个登录网站的用户。当他们单击注销按钮时,它会调用以下代码:

[HttpGet]
public async Task<IActionResult> Logout()
{
    await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
    HttpContext.Session.Clear();

    return RedirectToAction("Index", "Home");
}
Run Code Online (Sandbox Code Playgroud)

这成功地清除了浏览器中的所有 cookie,但是,如果我.AspNetCore.Cookies在注销之前获取会话 cookie 的值,然后在以后的请求中重新添加它,我就可以导航到需要用户身份验证的页面。

任何人都可以帮助解决这个问题?

注意:最初的问题是关于如何清除用户会话,但我后来意识到这实际上是关于 cookie 本身而不是服务器端会话的问题。

c# authentication asp.net-core

5
推荐指数
1
解决办法
2637
查看次数

标签 统计

asp.net-core ×2

c# ×2

.net ×1

authentication ×1

wcf ×1