架构师_程序员_码农网

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

搜索
查看: 19705|回复: 1

[ASP.NET] asp.net 用redis实现sso单点登录方案

[复制链接]
发表于 2016-7-22 13:41:38 | 显示全部楼层 |阅读模式
QQ截图20160722123759.jpg

缺点:

仅限于.net的网站,所有站点都是.net做的网站,和其他语言混合的话,原理上是可以的,但是,我没有做过。

第一步:

引用StackExchange.Redis

  1. PM> Install-Package StackExchange.Redis
复制代码


https://github.com/StackExchange/StackExchange.Redis

第二步:

引用Microsoft.Web.Redis.RedisSessionStateProvider

  1. Install-Package Microsoft.Web.RedisSessionStateProvider
复制代码


第三步:

配置web.config

  1. <system.web>
  2.     <sessionState mode="Custom" customProvider="MySessionStateStore" cookieName="__test_id__">
  3.       <providers>
  4.         <!-- For more details check https://github.com/Azure/aspnet-redis-providers/wiki -->
  5.         <!-- Either use 'connectionString' OR 'settingsClassName' and 'settingsMethodName' OR use 'host','port','accessKey','ssl','connectionTimeoutInMilliseconds' and 'operationTimeoutInMilliseconds'. -->
  6.         <!-- 'throwOnError','retryTimeoutInMilliseconds','databaseId' and 'applicationName' can be used with both options. -->
  7.         <!--
  8.           <add name="MySessionStateStore"
  9.             host = "127.0.0.1" [String]
  10.             port = "" [number]
  11.             accessKey = "" [String]
  12.             ssl = "false" [true|false]
  13.             throwOnError = "true" [true|false]
  14.             retryTimeoutInMilliseconds = "5000" [number]
  15.             databaseId = "0" [number]
  16.             applicationName = "" [String]
  17.             connectionTimeoutInMilliseconds = "5000" [number]
  18.             operationTimeoutInMilliseconds = "1000" [number]
  19.             connectionString = "<Valid StackExchange.Redis connection string>" [String]
  20.             settingsClassName = "<Assembly qualified class name that contains settings method specified below. Which basically return 'connectionString' value>" [String]
  21.             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]
  22.             loggingClassName = "<Assembly qualified class name that contains logging method specified below>" [String]
  23.             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]
  24.           />
  25.         -->
  26.         <add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" host="127.0.0.1" port="11511" accessKey="pass123" ssl="false" />
  27.         <!--<add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" host="" accessKey="" ssl="true" />-->
  28.       </providers>
  29.     </sessionState>
  30.     <compilation debug="true" targetFramework="4.0" />

  31.     <pages>
  32.       <namespaces>
  33.         <add namespace="System.Web.Helpers" />
  34.         <add namespace="System.Web.Mvc" />
  35.         <add namespace="System.Web.Mvc.Ajax" />
  36.         <add namespace="System.Web.Mvc.Html" />
  37.         <add namespace="System.Web.Routing" />
  38.         <add namespace="System.Web.WebPages" />
  39.       </namespaces>
  40.     </pages>
  41.   </system.web>
复制代码






上一篇:[StackExchange.Redis.ServerEndPoint]' violates the constraint of type paramet...
下一篇:不借助第三方实现AndroidPush消息推送服务
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
发表于 2018-12-29 09:42:05 | 显示全部楼层
....写的这是什么啊
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

免责声明:
码农网所发布的一切软件、编程资料或者文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To:help@itsvse.com

QQ|小黑屋|架构师 ( 鲁ICP备14021824号-2 )|网站地图

GMT+8, 2026-9-1 20:06

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表