asp.net 使用 Cas 单点登录 配置

1:  配置web.config
2:   获取登录用户名称,判断是否为单点登录,再处理登录问题


web.config

<?xml version="1.0"?>
<configuration>
	<configSections>
		<span style="color:#ff6666;"><section name="casClientConfig" type="DotNetCasClient.Configuration.CasClientConfiguration, DotNetCasClient"/></span>
		<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
			<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
				<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
				<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
					<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
					<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
					<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
					<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
				</sectionGroup>
			</sectionGroup>
		</sectionGroup>
	</configSections>
	<appSettings/>
	<connectionStrings/>
	<span style="color:#ff0000;"><casClientConfig casServerLoginUrl="http://192.168.10.10:8002/sap_CAS/login" casServerUrlPrefix="http://192.168.10.10:8002/sap_CAS" serverName="http://localhost:52862/" notAuthorizedUrl="~/NotAuthorized.aspx" cookiesRequiredUrl="~/CookiesRequired.aspx" redirectAfterValidation="true" gateway="false" renew="false" singleSignOut="true" ticketTimeTolerance="5000" ticketValidatorName="Cas20" proxyTicketManager="CacheProxyTicketManager" serviceTicketManager="CacheServiceTicketManager" gatewayStatusCookieName="CasGatewayStatus">
	</casClientConfig></span>
	
   <system.web>
		<span style="color:#ff0000;"><authentication mode="Forms">
			<forms loginUrl="http://192.168.10.10:8002/<span style="font-family: Arial, Helvetica, sans-serif;">sap</span><span style="font-family: Arial, Helvetica, sans-serif;">_CAS/login" timeout="30" defaultUrl="Default.aspx" cookieless="UseCookies" slidingExpiration="true"/></span>
		</authentication>
		<authorization>
			<deny users="?"/>
			<allow users="*"/>
		</authorization>
		<httpModules>
			<add name="DotNetCasClient" type="DotNetCasClient.CasAuthenticationModule,DotNetCasClient"/>
		</httpModules>
		<compilation debug="true"/></span>
</system.web>
	<system.webServer>
		<validation validateIntegratedModeConfiguration="false"/>
		<span style="color:#ff0000;"><modules>
			<remove name="DotNetCasClient"/>
			<add name="DotNetCasClient" type="DotNetCasClient.CasAuthenticationModule,DotNetCasClient"/>
		</modules></span>
	</system.webServer>
</configuration>
</pre><pre code_snippet_id="1905300" snippet_file_name="blog_20160928_6_5545162" name="code" class="csharp">
或者用户,验证登录


public void Login()
{
    if (HttpContext.Current != null)
    {
        //是否已经form验证?
        string username = HttpContext.Current.User.Identity.IsAuthenticated ? HttpContext.Current.User.Identity.Name : "";

        if (!string.IsNullOrEmpty(username))
        {//如果当前用户已登录单点登录系统
            var loginInfo = 。。。
            if (loginInfo != null)
            {
                //缓存loginInfo...                    
            }
        }
        else
        {
            Logout();
        }
    }
}



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值