当前位置: 首页 > 知识库问答 >
问题:

C#Siteminder身份验证

卫高明
2023-03-14

我正在尝试编写一些代码来连接到使用Siteminder身份验证的HTTPS站点。

我一直得到401。有什么想法吗?

我在这里读了一些不同的东西,但没有一个看起来真的很有帮助。我也在使用Fiddler/Firefox Tamper来窥探发生了什么。

这是到目前为止我在代码方面得到的信息:

try
        {

            Uri uri = new Uri("https://websiteaddresshere");
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri) as HttpWebRequest;

            request.Accept = "text/html, application/xhtml+xml, */*";

            request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko";
        //    request.Connection = "Keep-Alive";
           // request.Method = "Get";
           // request.Accept = "text";
            request.AllowAutoRedirect = true;
            request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

            Cookie emersoncookie = new Cookie("SMCHALLENGE",  "YES");
            emersoncookie.Domain = "mydomain";
            emersoncookie.Path = "/";




           // authentication
            var cache = new CredentialCache();
            cache.Add(uri, "False", new NetworkCredential("myusername", "mypassword"));

            request.Credentials = cache;


            // response.
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                using (Stream stream = response.GetResponseStream())
                {
                    XmlTextReader reader = new XmlTextReader(stream);
                    MessageBox.Show(stream.ToString());
                }
            }

        }
        catch (WebException exception)
        {
            string responseText;

            using (var reader = new StreamReader(exception.Response.GetResponseStream()))
            {
                responseText = reader.ReadToEnd();
                MessageBox.Show(responseText.ToString());
            }
        }

共有2个答案

邴和雅
2023-03-14

我无法让Jasen的代码工作。也许你的SM设置和我的不同。但对于SiteMinder,通常需要两步认证过程。下面的代码块适用于我:

        //Make initial request
        RestClient client = new RestClient("http://theResourceDomain/myApp");
        client.CookieContainer = new CookieContainer();
        IRestResponse response = client.Get(new RestRequest("someProduct/orders"));

        //Now add credentials.
        client.Authenticator = new HttpBasicAuthenticator("username", "password");
        //Get resource from the SiteMinder URI which will redirect to the correct API URI upon authentication.
        response = client.Get(new RestRequest(response.ResponseUri)); 

尽管这使用了RestSharp,但可以使用HttpClient甚至HttpWebRequest轻松复制它。

仰雅昶
2023-03-14

在MSDN网站上阅读了更多内容后,我决定走另一条路。

我最终将此作为一项服务,因为它需要在一天结束时成为一项服务,并执行了以下操作:

 CookieContainer emersoncookie = new CookieContainer();

            HttpWebRequest request = (HttpWebRequest)
            WebRequest.Create("https://websiteaddress");

            request.Credentials = new NetworkCredential("username", "password");
            request.CookieContainer = emersoncookie;

            request.Method = "GET";
            HttpWebResponse response = (HttpWebResponse)
            request.GetResponse();

            Stream resStream = response.GetResponseStream();

            using (Stream output = File.OpenWrite(@"c:\\somefolder\\somefile.someextention"))
            using (Stream input = resStream)
            {
                input.CopyTo(output);
            }

对于任何可能遇到Siteminder身份验证问题的人来说,这段代码工作得很好。

 类似资料:
  • 我有一个已经完成的j2ee(jsf、cdi、jpa)应用程序,它完美地使用了ApacheShiro,它工作得非常好,我喜欢Shiro注释(hasRole、hasPermission等)。 现在,该项目还必须能够通过SiteMinder进行身份验证,我的问题是: 我如何设置一个领域来处理SiteMinder身份验证而不丢失Shiro授权(似乎SiteMinder会在HTTP头中给我用户名和Rolen

  • 我的问题是,我们有一组运行SiteMinder但非常糟糕的遗留代码。它允许IIS匿名并避免使用Active Directory。 我们正在重建此应用程序,并希望将SiteMinder与IIS和集成。净额4.0。我知道我可以构建自己的安全框架,无需用户名和密码即可完成所有工作(因为我们不希望SiteMinder提供),但我想知道是否有办法使用内置的Windows身份验证(窗体或Windows)与Si

  • 本文向大家介绍C#验证身份证的函数,包括了C#验证身份证的函数的使用技巧和注意事项,需要的朋友参考一下 这段C#代码主要是验证身份证的开头和身份证的格式和长度是否正确,没有按照身份证的编码规则进行严格验证 更为复杂些的验证方法: 方法三: 以上所述就是本文的全部内容了,希望大家能够喜欢。

  • 身份验证 PDF版下载 企业应用中的URL链接可以通过OAuth2.0验证接口来获取员工的身份信息。 通过此接口获取员工身份会有一定的时间开销。对于频繁获取员工身份的场景,建议采用如下方案: 企业应用中的URL链接直接填写企业自己的页面地址; 员工跳转到企业页面时,企业校验是否有代表员工身份的cookie,此cookie由企业生成; 如果没有获取到cookie,重定向到OAuth验证链接,获取员工

  • 我有一个基本的apache2.4 HTTP Web服务器和tomcat7应用服务器。CA Siteminder Webagent在HTTP Webserver中配置,并使用mod\u代理将流量传递给应用程序服务器。当用户成功登录到SSO并将请求传递给部署在tomcat中的webapplication时,即要求标准的tomcat登录。 如何停止询问tomcat标准登录,以及如何在使用sitemind

  • 我有一些用于测试认证的Mifare Ultralight C标签。 我第一次使用应用程序NXP TagInfo阅读它时,我可以看到以下信息: 页面2C - 2F意味着它有默认的键“BREAKMEIFYOUCAN!”(< code > 425245414 b4d 454946594 f 5543414 e 21 )。 然后我运行我的Android应用程序,它基本上是这样做的: > 写入从第2C页到第