Please try and reply via the mailing list - there may be other people who can help here as well - also there may be other people in future with the same problem? First of all - the client does for you most of what you are trying to do in the examples given below. You don't need to write a form for login and you don't need to open streams to CAS. Simply set up your Web.Config as detailed in the wiki and instantiate the DotNetCASClientServiceValidate class: DotNetCASClientServiceValidate client = new DotNetCASClientServiceValidate(); Then call the authenticate method on your client object: userId = client.Authenticate(Request, Response, true); This will return you the username of the logged in user. The process of running that method will include, if appropriate, an automatic redirect to the CAs login page. You do all of this in the Page_Load of an aspx in your application which will act as the entry point for your application. All of this is detailed in the wiki docs: http://www.ja-sig.org/wiki/display/CASC/.Net+Cas+Client Have you read that? Pretty much all I'm doing is rehashing that so, if you're struggling to understand the wiki, then this may not make sense to you either... 111143252 wrote: > Thank you very much. > > I cannot express my idea, but your answer is very help to me. > > I am working in a completely .Net environment, > The problem I am facing is that I can't see > how I can retrieve the user name for an already > authenticated user. > > I use under way to customlize login forms of each service. > > Add this form in web application if want authenticate via CAS: > > action="" method="post"> >

username:

>

password:

> > > and in login.aspx: > > private const string CASHOST = "https://localhost:8443/"; > private void Page_Load(object sender, System.EventArgs e) > { > if(!this.IsPostBack) > { > string tkt = Request.QueryString["ticket"]; > string strFromUrl=FormsAuthentication.GetRedirectUrl("*",false); > string service = > Request.Url.ToString();//Request.Url.GetLeftPart(UriPartial.Path); > string redir = "index.htm"; //the homepage of this web application > if (tkt == null || tkt.Length == 0) > { > Response.Redirect(redir); > return; > } > string validateurl = CASHOST + "serviceValidate?" + "ticket=" + tkt > + "&" + "service=" + service; > System.Net.ServicePointManager.CertificatePolicy = new > TrustAllCertificatePolicy(); > StreamReader Reader = new StreamReader(new > WebClient().OpenRead(validateurl),System.Text.Encoding.Default); > string resp = Reader.ReadToEnd(); > NameTable nt = new NameTable(); > XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt); > XmlParserContext context = new XmlParserContext(null, nsmgr, null, > XmlSpace.None); > XmlTextReader reader = new XmlTextReader(resp, XmlNodeType.Element, > context); > string netid = null; > while (reader.Read()) > { > if (reader.IsStartElement()) > { > string tag = reader.LocalName; > if (tag=="user") > { > netid = reader.ReadString(); > } > } > } > reader.Close(); > > if (netid == null) > { > Response.Redirect(redir); > return ; > } > else > { > Login(netid); // set cookie and other infomation of current user > } > } > > Then modify the casLoginView.jsp (CAS3.1.1) > > <%@ page contentType="text/html; charset=gb2312"%> > <%@ page session="false" %> > <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> > <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> > <[EMAIL PROTECTED] import="org.springframework.util.StringUtils"%> > > <% > String username = request.getParameter("username"); > username = new String(username.getBytes("iso8859_1")); > String password = request.getParameter("password"); > String service = request.getParameter("service"); > if ((username==null)||(password==null)){ > response.sendRedirect("index.jsp"); > } > %> > > action=""https://localhost:8443/login" + > (StringUtils.hasText(request.getQueryString()) ? "?" + > request.getQueryString() : ""))%>" > > > value="<%=username%>" /> > value="<%=password%>" /> > " /> > > > > > > > > I think It is a very stupid way, > but I have no idead to resolve the second problem I was ask. > > Zhiqi Tyan, 2007-11-16 > > > 在2007-11-16,"Paul Hunnisett" <[EMAIL PROTECTED]> 写道: > > I've copied in the CAS mailing list as it may be useful for others to > get in on this. > > If I understand your first question properly then you want to log into > one application via CAS and then proxy into others? > > The process of logging in via the .net client is reasonably simple. You > just need to set up your Web.Config as detailed in the wiki and then > it's just a case of using the Authenticate() method. This will return > you a username once the user has been redirected via CAS and > successfully logged in. > > The proxy side of things is, in theory, also simple. If, however, > you're working in a completely .Net environment then you have the > problem that the .Net client doesn't yet support getting proxy tickets. > It does, however, support authentication via proxy tickets which you > could get, for example, if one of your apps was Java. > > Getting proxy tickets will be in the next release of the client which > hopefully won't be too far away. > > As to your second question; I believe there is a way of customising the > CAS login form to display appropriate "look and feel" for each service. > Others on the list may have a clearer idea of how to set this up than I > do... > > I hope that was some help. > > Paul Hunnisett > UWE > > 111143252 wrote: > > Thanks very much. > > > > It is useful to me. > > > > > > Now, I have two problem (Can you help me) > > > > 1. eg: A system include some applications, base on web forms > > > > and window forms. A visitor was sign in a application, > > > > How to get the signed user's name from CAS server > > > > when other applications is loaded ? > > > > > > 2. There is only one page to login in CAS, > > > > Visitors hope to sign in system on the home page of every application. > > > > How to design each login form ? > > > > > > Happy erevy day, *_* > > > > Zhiqi Tyan , 2007-11-16 > > > > > > > > 在2007-11-15,"Paul Hunnisett" <[EMAIL PROTECTED]> 写道: > > > > No problem - The complete VS project is available from subversion at: > > > > https://www.ja-sig.org/svn/cas-clients/dotnet-client/trunk/dotnet-client/ > > > > with the specific cs file at: > > > > https://www.ja-sig.org/svn/cas-clients/dotnet-client/trunk/dotnet-client/DotNetCASClient/DotNetCASClient.cs > > > > I hope that helps. > > > > Happy everyday to you too! > > > > Paul Hunnisett > > UWE > > > > 111143252 wrote: > > > Dear Paul Hunnisett: > > > > > > My name is Zhiqi Tyan, > > > > > > A program designer of China. > > > > > > I was read you project in > > > http://www.ja-sig.org/wiki/display/CASC/.Net+Cas+Client , > > > > > > I add DotNetCASClient.dll in my project that designed by Vs2003, > > > > > > but something wrong. It is right in Vs2005. > > > > > > In China, the document about CAS is so litter that I have to read > > > > > > English document with my poor English. > > > > > > Could you give me your sorce code of DotNetCASClient.dll ? > > > > > > Thanks. > > > > > > Happy everyday! > > > > > > > > > Zhiqi Tyan > > > > > > LinFen City of Shanxi province, China > > > > > > Tel: 86-0357-2055400 > > > > > > > > > > > > > > > > > > > > > > > > > > > ------------------------------------------------------------------------ > > > This incoming email to UWE has been independently scanned for viruses by > > > McAfee anti-virus software and none were detected > > > > > > > > > This email was independently scanned for viruses by McAfee anti-virus software and none were found > > > > ------------------------------------------------------------------------ > > This incoming email to UWE has been independently scanned for viruses by > > McAfee anti-virus software and none were detected > > > > > > This email was independently scanned for viruses by McAfee anti-virus software and none were found > > ------------------------------------------------------------------------ > This incoming email to UWE has been independently scanned for viruses by > McAfee anti-virus software and none were detected > This email was independently scanned for viruses by McAfee anti-virus software and none were found
_______________________________________________
Yale CAS mailing list
[email protected]
http://tp.its.yale.edu/mailman/listinfo/cas

Reply via email to