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();
}
}
}