gpt4 book ai didi

c# - 连接被拒绝 - Redis 用于 ASP.Net Core 2.1 中的数据保护 key

转载 作者:IT王子 更新时间:2023-10-29 06:04:58 24 4
gpt4 key购买 nike

我正在阅读 Microsoft 的这篇文章: https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/implementation/key-storage-providers?view=aspnetcore-2.1

我正在尝试执行以下操作:

    services.AddDataProtection()
.PersistKeysToRedis(ConnectionMultiplexer.Connect("localhost"));

错误堆栈:

app    | Unhandled Exception: System.AggregateException: One or more errors occurred. (Connection refused) ---> System.Net.Sockets.SocketException: Connection refused
app | at System.Net.Sockets.Socket.BeginConnectEx(EndPoint remoteEP, Boolean flowContext, AsyncCallback callback, Object state)
app | at System.Net.Sockets.Socket.UnsafeBeginConnect(EndPoint remoteEP, AsyncCallback callback, Object state, Boolean flowContext)
app | at System.Net.Sockets.Socket.PostOneBeginConnect(MultipleAddressConnectAsyncResult context)
app | --- End of stack trace from previous location where exception was thrown ---
app | at System.Net.Sockets.Socket.DoMultipleAddressConnectCallback(Object result, MultipleAddressConnectAsyncResult context)
app | at System.Net.Sockets.Socket.DoDnsCallback(IAsyncResult result, MultipleAddressConnectAsyncResult context)
app | at System.Net.Sockets.Socket.BeginConnect(String host, Int32 port, AsyncCallback requestCallback, Object state)
app | at System.Net.Sockets.Socket.ConnectAsync(String host, Int32 port)
app | at System.Net.Sockets.SocketTaskExtensions.ConnectAsync(Socket socket, String host, Int32 port)
app | at StackExchange.Redis.SocketManager.BeginConnect(EndPoint endpoint, ISocketCallback callback, ConnectionMultiplexer multiplexer, TextWriter log) in c:\code\StackExchange.Redis\StackExchange.Redis\StackExchange\Redis\SocketManager.cs:line 194

我正在使用 Docker:

redis:
image: redis:alpine
container_name: redis
ports:
- "6379:6379"

有什么想法吗?

最佳答案

需要引用容器和端口

services.AddDataProtection()
.PersistKeysToRedis(ConnectionMultiplexer.Connect("redis:6379"));

我还在配置中添加了 abortConnect=false"

REDIS_CONNECTION_STRING = "redis:6379,abortConnect=false"


var redis = ConnectionMultiplexer.Connect(Environment.GetEnvironmentVariable("REDIS_CONNECTION_STRING"));
services.AddDataProtection().PersistKeysToRedis(redis, "DataProtection-Keys");

关于c# - 连接被拒绝 - Redis 用于 ASP.Net Core 2.1 中的数据保护 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51927834/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com