如何在Azure中为会话状态定义连接字符串 [英] How to define connection string for session state in Azure
问题描述
我正在使用RedisSessionStateProvider
使用类似这样的程序
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 WebSite的应用程序设置"中定义连接字符串
Using that you can now define the connection string in the App Settings of Azure WebSites
这篇关于如何在Azure中为会话状态定义连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!