当前位置: 首页>>代码示例>>C#>>正文


C# Response.Sign方法代码示例

本文整理汇总了C#中Response.Sign方法的典型用法代码示例。如果您正苦于以下问题:C# Response.Sign方法的具体用法?C# Response.Sign怎么用?C# Response.Sign使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Response的用法示例。


在下文中一共展示了Response.Sign方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnLoad

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
              try
              {
            #region Custom Attributes
            // If you need to add custom attributes, uncomment the following code
            var attributeStatement = new AttributeStatement();
            attributeStatement.Attributes.Add(new Atp.Saml2.Attribute("email", SamlAttributeNameFormat.Basic, null,
                                                                                     "[email protected]"));
            attributeStatement.Attributes.Add(new Atp.Saml2.Attribute("FirstName", SamlAttributeNameFormat.Basic, null,
                                                                                     "John"));
            attributeStatement.Attributes.Add(new Atp.Saml2.Attribute("LastName", SamlAttributeNameFormat.Basic, null, "Smith"));

            if (Session["username"] != null && Session["previoususername"] != null)
            {
              if (!Session["username"].ToString().ToLower().Equals(Session["previoususername"].ToString().ToLower()))
            attributeStatement.Attributes.Add(new Atp.Saml2.Attribute("samlsessionstate", SamlAttributeNameFormat.Basic, null, "new"));
            }
            #endregion

            // Set External Account Id for Metanga
            var externalAccountId = "XAF10964";
            if (Session["username"] != null)
            {
              externalAccountId = Session["username"].ToString();
            }
            else
            {
              Session["username"] = externalAccountId;
              Session["previoususername"] = externalAccountId;
            }

            var consumerServiceUrl = Helper.GetUrl("LinkSelfcareLogin");

            // Use the local user's local identity.
            var subject = new Subject(new NameId(User.Identity.Name)) {NameId = {NameIdentifier = externalAccountId}};
            subject.SubjectConfirmations.Add(new SubjectConfirmation(SamlSubjectConfirmationMethod.Bearer)
                                            {
                                              SubjectConfirmationData = new SubjectConfirmationData { Recipient = consumerServiceUrl }
                                            });

            // Create a new authentication statement.
            var authnStatement = new AuthnStatement
            {
              AuthnContext = new AuthnContext
              {
            AuthnContextClassRef = new AuthnContextClassRef(SamlAuthenticateContext.Password)
              }
            };

            var issuer = new Issuer(GetAbsoluteUrl("~/"));
            var samlAssertion = new Assertion { Issuer = issuer, Subject = subject };
            samlAssertion.Statements.Add(authnStatement);
            samlAssertion.Statements.Add(attributeStatement);

            // Get the PFX certificate with Private Key.
            var filePath = Path.Combine(HttpRuntime.AppDomainAppPath, "metangasso.pfx");
            const string pwd = "123";
            var x509Certificate = new X509Certificate2(filePath, pwd, X509KeyStorageFlags.MachineKeySet);

            if (!x509Certificate.HasPrivateKey)
              return;

            // Create a SAML response object.
            var samlResponse = new Response
            {
              // Assign the consumer service url.
              Destination = consumerServiceUrl,
              Issuer = issuer,
              Status = new Status(SamlPrimaryStatusCode.Success, null)
            };

            // Add assertion to the SAML response object.
            samlResponse.Assertions.Add(samlAssertion);

            // Sign the SAML response with the certificate.
            samlResponse.Sign(x509Certificate);

            var targetUrl = Helper.GetUrl("LinkSelfcareBilling") + "?SSO=true";
            if (Session["SsoLink"] != null)
            {
              targetUrl = Session["SsoLink"].ToString();
            }

            // Send the SAML response to the service provider.
            samlResponse.SendPostBindingForm(Response.OutputStream, consumerServiceUrl, targetUrl);
              }
              catch (Exception exception)
              {
            Trace.Write("IdentityProvider", "An Error occurred", exception);
              }
        }
开发者ID:MetangaSDK,项目名称:Metanga-RESTful-SDK,代码行数:93,代码来源:ViewMetanga.aspx.cs


注:本文中的Response.Sign方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。