gpt4 book ai didi

azure - 如何在 Azure 中定义 session 状态的连接字符串

转载 作者:行者123 更新时间:2023-12-04 10:15:57 25 4
gpt4 key购买 nike

我正在使用 RedisSessionStateProvider 使用像这样的过程 https://azure.microsoft.com/en-us/documentation/articles/web-sites-dotnet-session-state-caching/

我在web.config中定义了它的连接字符串,在本例中是XXXXXX

 <system.web>
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.5" />
<globalization culture="es-CO" uiCulture="es" />
<customErrors mode="Off" />
<sessionState mode="Custom" customProvider="SessionStateStore">
<providers>
<add name="SessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" connectionString="XXXXXX" throwOnError="true" applicationName="NominappSession" />
</providers>
</sessionState>
</system.web>

我不想将连接字符串放在源代码中。那么我如何使用Azure中的设置来定义这个连接字符串呢?

我从github部署到azure,所以它使用Kudu。我没有外部 CI 服务器。

请问有什么建议吗?

最佳答案

我做到了:)

为此,您需要将连接字符串定义为环境变量,而不是典型的连接字符串。并在 session 状态下提供使用环境变量名称。

这样:

  <appSettings>
<add key="REDIS_CONNECTION_STRING" value="redis,allowAdmin=true" />
</appSettings>
<system.web>
<sessionState mode="Custom" customProvider="SessionStateStore">
<providers>
<add name="SessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" connectionString="REDIS_CONNECTION_STRING" applicationName="REDIS_SESSION_APPLICATION_NAME" throwOnError="true" />
</providers>
</sessionState>
</system.web>

现在您可以使用它在 Azure 网站的应用程序设置中定义连接字符串

关于azure - 如何在 Azure 中定义 session 状态的连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35529052/

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