c# - Cas 4 attributes not return in ASP
问题描述
I have a project that redirect user to cas server and after user log in redirect it to my local (I'm using virtual host on IIS my.uk.ac.ir). Problem is that when it returns it doesnt return attribute. my project is on .net4.5.2 and using tls12
this is the original project that I modified. https://github.com/casinthecloud/dotnet-cas-client-demo
this is the link to modified project: https://github.com/HamidRezaAshkiyan/dotnet-cas-client-demo my modification is on dev branch.
Here is my web.config:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="casClientConfig" type="DotNetCasClient.Configuration.CasClientConfiguration, DotNetCasClient"/>
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.5.2"/>
<authentication mode="Forms">
<forms name=".DotNetCasClientAuth" loginUrl="https://gate.uk.ac.ir" cookieless="UseCookies"/>
</authentication>
<httpModules>
<add name="DotNetCasClient" type="DotNetCasClient.CasAuthenticationModule,DotNetCasClient"/>
</httpModules>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<remove name="DotNetCasClient"/>
<add name="DotNetCasClient" type="DotNetCasClient.CasAuthenticationModule,DotNetCasClient"/>
</modules>
</system.webServer>
<casClientConfig casServerLoginUrl="https://gate.uk.ac.ir" casServerUrlPrefix="https://gate.uk.ac.ir" serverName="https://my.uk.ac.ir/" notAuthorizedUrl="~/NotAuthorized.aspx" cookiesRequiredUrl="~/CookiesRequired.aspx" redirectAfterValidation="true" gateway="false" renew="false" singleSignOut="true" ticketTimeTolerance="5000" ticketValidatorName="Cas10" proxyTicketManager="CacheProxyTicketManager" serviceTicketManager="CacheServiceTicketManager" gatewayStatusCookieName="CasGatewayStatus"/>
</configuration>
this is my index page where redirects after login:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="dotnet_cas_client_demo.secure.index" %>
<asp:Content ID="Content1" ContentPlaceHolderID="content" runat="server">
<ul class="nav nav-tabs">
<li><a href="/index.aspx">Call the /index.aspx page</a></li>
<li class="active"><a href="/secure/index.aspx">You are on the /secure/index.aspx page</a></li>
<!-- #### change with your own CAS server and your host name #### -->
<li><a href="http://gate.uk.ac.ir/logout?service=https://my.uk.ac.ir/">Call the CAS logout</a></li>
</ul>
<h3>
<p>username: <span id="username" runat="server" /></p>
<p>AttributeCount: <span id="attributes" runat="server" /></p>
<p>Attribute: <span id="attribute" runat="server" /></p>
</h3>
</asp:Content>
this is the backend code:
using System;
namespace dotnet_cas_client_demo.secure
{
public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// get the current authenticated user
username.InnerText = System.Web.HttpContext.Current.User.Identity.Name;
attributes.InnerText = CasAuthentication.CurrentPrincipal.Assertion.Attributes.Count.ToString();
}
}
}
I'm not sure that the right way of getting the attributes or not.
I've tried this solution for java but not helped me. Cas no attributes come to client
there where similar problem on php and my coworkers solved it with cas protocol 3 and i saw similar on the answer above.
解决方案
经过大量谷歌搜索后,我发现该库不支持 cas 协议 3,并且我发现了另一个在 .net core 3 上运行并默认支持 3 的库: https ://github.com/akunzai/GSS.Authentication.CAS
它帮助我获得了属性。
Apereo 库正在支持协议 3。
推荐阅读
- sql - 嵌套游标性能调优
- node.js - Xero Api NodeJS - 无效授权问题
- plotly - 如何在绘图破折号框架中居中对齐表格?
- html - 我如何在 html 中的图像上包含 2 行文本(标题和子标题)和框阴影
- reactjs - 返回调度函数和返回一个
- plot - 如何使用 GNUPlot 在没有 x/y 抽动的情况下获取绘图图像的轴值?
- flutter - 如何为小部件(视图)启动 ViewModel
- c++ - 从源代码构建 Qt 使其接受中文输入
- javascript - 道具更改时反应自定义挂钩运行过程
- eclipse - 如何分配一些快捷方式以在 Eclipse IDE 中添加一些片段?