ASP.NET MVC配置客户端单点登录CAS
来源:互联网 发布:电脑右下角出淘宝广告 编辑:程序博客网 时间:2024/05/16 00:35
DEMON可以查看https://www.cnblogs.com/woxpp/p/4653769.html
本文只说明客户端的配置
1.WEB.CONFIG
添加以下节点,需要注意的事项
<configuration>
<configSections>
<section name="casClientConfig" type="DotNetCasClient.Configuration.CasClientConfiguration, DotNetCasClient"/>
<casClientConfig
casServerLoginUrl="http://***:8080/sso/login" ---单点登录地址
casServerUrlPrefix="http://***:8080/sso" ---单点登录地址
serverName="http://**:52801" ---客户端配置地址
notAuthorizedUrl="~/Login/Index" ---客户端登录界面
cookiesRequiredUrl="~/Admin/Home/Index" ---客户端登录成功后的跳转界面
redirectAfterValidation="true"
gateway="false"
renew="false"
singleSignOut="true"
ticketTimeTolerance="5000"
ticketValidatorName="Cas20"
proxyTicketManager="CacheProxyTicketManager"
serviceTicketManager="CacheServiceTicketManager"
gatewayStatusCookieName="CasGatewayStatus" />
<system.web>
<!--<authentication mode="None" />-->
<authentication mode="Forms">
<forms
loginUrl="http://**:8080/sso/login" ---单点登录地址
timeout="30"
defaultUrl="http://**:52801" ---客户端配置地址
cookieless="UseCookies"
slidingExpiration="true"
path="/"
/>
</authentication>
<system.webServer>
<modules>
<remove name="FormsAuthenticationModule" />
<remove name="DotNetCasClient"/>
<add name="DotNetCasClient" type="DotNetCasClient.CasAuthenticationModule,DotNetCasClient"/>
</modules>
</system.webServer>
<system.diagnostics>
<trace autoflush="true" useGlobalLock="false" />
<sharedListeners>
<!--Writing trace output to a log file is recommended.
IMPORTANT:
The user account under which the containing application pool runs
must have privileges to create and modify the trace log file.-->
<add name="TraceFile"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="C:\inetpub\logs\LogFiles\DotNetCasClient.Log"
traceOutputOptions="DateTime" />
</sharedListeners>
<sources>
<!--Provides diagnostic information on module configuration parameters.-->
<source name="DotNetCasClient.Config" switchName="Config" switchType="System.Diagnostics.SourceSwitch" >
<listeners>
<add name="TraceFile" />
</listeners>
</source>
<!--Traces IHttpModule lifecycle events and meaningful operations performed therein.-->
<source name="DotNetCasClient.HttpModule" switchName="HttpModule" switchType="System.Diagnostics.SourceSwitch" >
<listeners>
<add name="TraceFile" />
</listeners>
</source>
<!--Provides protocol message and routing information.-->
<source name="DotNetCasClient.Protocol" switchName="Protocol" switchType="System.Diagnostics.SourceSwitch" >
<listeners>
<add name="TraceFile" />
</listeners>
</source>
<!--Provides details on security operations and notable security conditions.-->
<source name="DotNetCasClient.Security" switchName="Security" switchType="System.Diagnostics.SourceSwitch" >
<listeners>
<add name="TraceFile" />
</listeners>
</source>
</sources>
<switches>
<!--Set trace switches to appropriate logging level. Recommended values in order of increasing verbosity:
- Off
- Error
- Warning
- Information
- Verbose
Config category displays detailed information about CasAuthenticationModule configuration.
The output of this category is only displayed when the module is initialized, which happens
for the first request following application/server startup.-->
<add name="Config" value="Information"/>
<!--Set this category to Verbose to trace HttpModule lifecycle events in CasAuthenticationModule.
This category produces voluminous output in Verbose mode and should be avoided except for
limited periods of time troubleshooting vexing integration problems.-->
<add name="HttpModule" value="Verbose"/>
<!--Set to Verbose to display protocol messages between the client and server.
This category is very helpful for troubleshooting integration problems.-->
<add name="Protocol" value="Information"/>
<!--Displays important security-related information.-->
<add name="Security" value="Information"/>
</switches>
</system.diagnostics>
</configuration>
2. LoginController配置
[Authorize] //这个一定要配置,不然服务端不知道需要拦截那个方法
public ActionResult Index()
{
string userId = "";
if (!System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
{
DotNetCasClient.CasAuthentication.RedirectToLoginPage();
return View();
}
else
{
userId = CasAuthentication.CurrentPrincipal.Identity.Name; //获取服务端传过来的ID
}
……//写入SESSION
Response.Redirect("~/Admin/Home/Index"); //跳转到登陆成功后的界面
return View();
}
3.退出
项目需求是需要跳转到
http://**:8080/sso/logout
@using DotNetCasClient;// 退出
$('#loginOut').click(function () {
$.messager.confirm('系统提示', '您确定要退出本次登录吗?', function (r) {
if (r) {
//window.location.href = "/Login/Index/";
$.post("/Login/LognOut", function (r) {
if(r=="OK")
{
top.location.href = "http://**:8080/sso/logout";
}
});
}
});
})
3.1Controller层
消除SESSION
public ActionResult LognOut()
{
Session["UserInfo"] = null;
Session.RemoveAll();
Session.Clear();
return Content("OK");
//return View();
}
实现跨域访问:
在Admin View的web.config配置文件中添加
<system.webServer>
<handlers>
<removename="BlockViewHandler"/>
<addname="BlockViewHandler"path="*"verb="*"preCondition="integratedMode"type="System.Web.HttpNotFoundHandler" />
</handlers>
<httpProtocol>
<customHeaders>
<addname="Access-Control-Allow-Origin"value="*" />
<addname="Access-Control-Allow-Headers"value="Content-Type" />
<addname="Access-Control-Allow-Methods"value="GET, POST, PUT, DELETE, OPTIONS" />
</customHeaders>
</httpProtocol>
</system.webServer>
相关文章:
http://www.cnblogs.com/zhenyulu/archive/2013/01/22/2870936.html
配置web.config的详细信息参见
https://wiki.jasig.org/display/CASC/.Net+Cas+Client
- ASP.NET MVC配置客户端单点登录CAS
- cas单点登录客户端(asp.net mvc4)配置
- asp.net 使用 Cas 单点登录 配置
- Cas单点登录客户端配置
- 单点登录学习(3)CAS客户端配置
- 单点登录(四)cas客户端配置
- cas 单点登录服务端客户端配置
- CAS单点登录服务端与客户端配置
- Asp.net Mvc4 使用Cas单点登录
- 单点登录CAS系列8-客户端配置单点登出
- CAS单点登录配置
- CAS单点登录配置
- CAS单点登录配置
- asp.net MVC 中 单点登录
- Cas单点登录的服务器端和客户端的配置
- Mvc4单点登录之三Cas 客户端配置
- Cas单点登录的服务器端和客户端的配置
- cas单点登录系统:客户端(client)详细配置
- 我为什么建议你发年终奖前跳槽?
- iOS开发 非常全的三方库、插件、大牛博客等等
- Struts2(十)---拦截器
- 涨跌幅判断长庄还是短庄
- 使用layer 弹出对话框 子父页面相互参数传递 父页面获取子页面参数实例
- ASP.NET MVC配置客户端单点登录CAS
- NTC热敏电阻温度计算公式
- [转]【OpenCV入门教程之八】线性邻域滤波专场:方框滤波、均值滤波与高斯滤波
- Python 分词及词云绘图
- 数据库主键的作用
- Win10+ubuntu16.04双系统的安装步骤
- 添加数据
- 求助 升级了项目所有架包,然后报错
- Android简单而强大的骨骼动画视图