C # Azure Storage-the configuration of distributed cache Redis in session

Source: Internet
Author: User
Tags naming convention

1. Start

For distributed cache, the usual session processing is a user corresponding to a distributed machine, if the machine is hanging in the middle or can not handle the user session, the user's session will be lost, unpredictable errors occur. Such as:

If you use Redis's distributed cache, you can avoid the above situation. Because the session is stored in Redis, there will be no missing cases, even if server a hangs up halfway. Such as:

2. Code

1) in the Package Manager, enter the following package, install

Install-package Microsoft.Web.RedisSessionStateProvider

2) You can see that the following code is automatically added in Web. config:

<sessionState mode="Custom" customProvider="MySessionStateStore" timeout="30">
        <!-- For more details check https://github.com/Azure/aspnet-redis-providers/wiki --> <!-- Either use ‘connectionString‘ OR ‘settingsClassName‘ and ‘settingsMethodName‘ OR use ‘host‘,‘port‘,‘accessKey‘,‘ssl‘,‘connectionTimeoutInMilliseconds‘ and ‘operationTimeoutInMilliseconds‘. -->
        <!-- ‘throwOnError‘,‘retryTimeoutInMilliseconds‘,‘databaseId‘ and ‘applicationName‘ can be used with both options. -->
          <add name="MySessionStateStore" host = "" [String]
            port = "" [number]
            accessKey = "" [String]
            ssl = "false" [true|false]
            throwOnError = "true" [true|false]
            retryTimeoutInMilliseconds = "5000" [number]
            databaseId = "0" [number]
            applicationName = "" [String]
            connectionTimeoutInMilliseconds = "5000" [number]
            operationTimeoutInMilliseconds = "1000" [number]
            connectionString = "<Valid StackExchange.Redis connection string>" [String]
            settingsClassName = "<Assembly qualified class name that contains settings method specified below. Which basically return ‘connectionString‘ value>" [String]
            settingsMethodName = "<Settings method should be defined in settingsClass. It should be public, static, does not take any parameters and should have a return type of ‘String‘, which is basically ‘connectionString‘ value.>" [String]
            loggingClassName = "<Assembly qualified class name that contains logging method specified below>" [String]
            loggingMethodName = "<Logging method should be defined in loggingClass. It should be public, static, does not take any parameters and should have a return type of System.IO.TextWriter.>" [String]
            redisSerializerType = "<Assembly qualified class name that implements Microsoft.Web.Redis.ISerializer>" [String] />
        <add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" host="ceswebchat.redis.cache.chinacloudapi.cn" accessKey="m1JuDEstaqA+xxxxxxxxxxx" ssl="false" throwOnError = "true" retryTimeoutInMilliseconds = "5000" connectionTimeoutInMilliseconds = "5000" operationTimeoutInMilliseconds = "1000" databaseId = "0" />

As you can see, enter the information you need. Very simple

    • Host–redis Cache's host Name/endpoint
    • port– uses the SSL port or non-SSL port of your Redis cache, depending on the value of your SSL setting
    • accesskey–redis Cache keys
    • ssl–true (Secure Communication between cache/client), otherwise set to False
      • disables NON-SSL port by default for enabling Non-ssl Port, see Access Ports
    • throwonerror–true (throws an exception in case of an event error), otherwise set to False. You can do this in static properties MICROSOFT.WEB.R Edis. Redissessionstateprovider.lastexception checks for exception information, which defaults to true.
    • retrytimeoutinmilliseconds– retry operation during this interval (in milliseconds)
    • databaseid– Specifies that a database is used to store cached input data. If not specified, the default value is 0. The
    • applicationname– cache key is stored in Redis with the naming convention:{<application name>_<session id>}_data, This parameter is optional if multiple applications share the same key. If you do not set this parameter, the default value will be used.
    • connectiontimeoutinmilliseconds– This setting overrides the ConnectTimeout parameter setting. If not set, the default ConnectTimeout value of 5000 is used, please refer to Stackexchange.redis configuration model for details.
    • operationtimeoutinmilliseconds– This setting overrides the Synctimeout parameter setting. If not set, the default Synctimeout value of 1000 is used, please refer to Stackexchange.redis configuration model for details.

C # Azure Storage-the configuration of the distributed cache Redis in session

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.