如何在 Azure 中为会话状态定义连接字符串 [英] How to define connection string for session state in Azure
问题描述
我正在使用 RedisSessionStateProvider
使用这样的过程 https://azure.microsoft.com/en-us/documentation/articles/web-sites-dotnet-session-state-caching/
I am using the RedisSessionStateProvider
using a procedimient like this https://azure.microsoft.com/en-us/documentation/articles/web-sites-dotnet-session-state-caching/
我在web.config
中定义了它的连接字符串,在这个例子中是XXXXXX
.
I define its connection string in web.config
, in this example is 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 中的设置来定义这个连接字符串呢?
I dont want to put the connection string in the source code. So how can i using the settings in Azure to define this connection string?
我从 github 部署到 azure,所以它使用 Kudu.我没有外部 CI 服务器.
I deploy to azure from github, so it uses Kudu. I dont have an external CI server.
有什么建议吗?
推荐答案
我做到了:)
为此,您需要将连接字符串定义为环境变量,而不是典型的连接字符串.并在会话状态下提供使用环境变量名称.
To do that you need to define the connection string as a environment variable, not as a typical connection string. And in the sesion state provide use the environment variable name.
这边:
<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 网站的应用设置中定义连接字符串
Using that you can now define the connection string in the App Settings of Azure WebSites
这篇关于如何在 Azure 中为会话状态定义连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!