c#cas客户端安装笔记

1、官方下载.net 客户端dll

在工程中加载dll

webconfig中配置

<configSections>

        <sectionname="casClientConfig"type="DotNetCasClient.Configuration.CasClientConfiguration, DotNetCasClient"/>

    </configSections>

 

 

    <casClientConfig

        //cas服务端登录页面

        casServerLoginUrl="http://192.168.12.196/cas/login"

        //cas服务端验证

        casServerUrlPrefix="http://192.168.12.196/cas"

        //跳转的页面,只取到http://localhost:3273/

        serverName="http://localhost:3273/ExampleWebSite"

        notAuthorizedUrl="~/NotAuthorized.aspx"

        cookiesRequiredUrl="~/CookiesRequired.aspx"

        redirectAfterValidation="true"

        gateway="false"

        renew="false"

        singleSignOut="true"

        ticketTimeTolerance="5000"

        ticketValidatorName="Cas20"

        serviceTicketManager="CacheServiceTicketManager"

        gatewayStatusCookieName="CasGatewayStatus" />

    <system.web>

 

.net 自己的Forms认证这的配置也很重要,

<authenticationmode="Forms">

            <forms

                loginUrl="http://192.168.12.196/cas/login"

                timeout="30"

                defaultUrl="~/Default.aspx"

                cookieless="UseCookies"

                slidingExpiration="true"

           //发布到外网的话path="/"

           path="/ExampleWebSite/"

               />    

        </authentication>

    <authorization>

      <denyusers="?"/>

      <allowusers="*"/>

    </authorization

 

最后就是httpModel的配置了

<httpModules>

      <addname="DotNetCasClient"type="DotNetCasClient.CasAuthenticationModule,DotNetCasClient"/>

    </httpModules>

//跳回的地址=serverName+path+"跳转前的页面"

//跳回页面取数据方法

using DotNetCasClient;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        getUserInfo();
    }

    private void getUserInfo()
    {
        if (CasAuthentication.ServiceTicketManager != null)
        {
            HttpCookie ticketCookie = Request.Cookies[FormsAuthentication.FormsCookieName];

            if (ticketCookie != null)
            {
                FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(ticketCookie.Value);
                if (ticket != null)
                {
                    CasAuthenticationTicket casTicket = CasAuthentication.ServiceTicketManager.GetTicket(ticket.UserData);
                    if (casTicket != null)
                    {
                        TextBox1.Text = casTicket.NetId;
                        TextBox2.Text = casTicket.Assertion.PrincipalName;
                    }
                }
            }
           
        }
    }
}

 //单点退出

修改DotNetCasClient.cs页面

public static void SingleSignOut()
        {
            Initialize();

            HttpContext context = HttpContext.Current;
            HttpResponse response = context.Response;


            // Necessary for ASP.NET MVC Support.
            if (context.User.Identity.IsAuthenticated)
            {
                ClearAuthCookie();
                //update by songjg logout into login

                //注销页面

                //string singleSignOutRedirectUrl = UrlUtil.ConstructSingleSignOutRedirectUrl();

                //修改重定向到login页面

                string strLoginUrl = CasClientConfig.CasServerLoginUrl;
                // Leave endResponse as true.  This will throw a handled ThreadAbortException
                // but it is necessary to support SingleSignOut in ASP.NET MVC applications.
                response.Redirect(strLoginUrl, true);
                //update by songjg logout into login
            }
        }

生成新的动态库DotNetCasClient.dll

web.config

去掉重定向配置

notAuthorizedUrl="~/NotAuthorized.aspx" 改为

notAuthorizedUrl=""

不改会发生重定向退出事件

protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Session.Clear();
        CasAuthentication.SingleSignOut();
     }

2、服务端的源码中AssemblyInfo.cs.tmpl文件去掉.tmpl 编译动态库工程。工程就能运行起来

 

另一种办法,不用重编译代码,只要修改相应文件就能满足退出到登录页面

配置PHP CLIENT6. 如何实现单点注销
       注销通过转到http://hostname:port/cas/logout时,注销成功后,转到成功提示页面。如果需要指定注销成功后的页面,有两点要做:

1、 打开tomcat6.0\cas\WEB-INF\cas-server.xml,找到下面代码:

 

       <bean id="logoutController" class="org.jasig.cas.web.LogoutController"

              p:centralAuthenticationService-ref="centralAuthenticationService"

              p:logoutView="casLogoutView"

              p:warnCookieGenerator-ref="warnCookieGenerator"

              p:ticketGrantingTicketCookieGenerator-ref="ticketGrantingTicketCookieGenerator"

/>

加入p:followServiceRedirects ="True"参数。

2、修改注销按钮的跳转页面:

http://hostname:port/cas/logout?service=http://what-you-want-to

http://hi.baidu.com/spanlessbug/item/1d5ff3cad25bf5d6964452b5

 

 

 

cas     response.spush() 有关  去掉这句cas就正常了。待验证?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值