SAML Idp Creation taking too much time










0















I am using "Kentor.AuthServices.dll" and "Kentor.AuthServices.Mvc.dll" in my code to allowing Single sign on with ADFS server and it is working fine but the problem is that it is taking around more than 1 min show the adfs login screen.



I have debugged the code and record the timing and found the all the code working fine but identity provider creating code is taking more than 1 min.



I am not able to understand why it is taking too much time.



I am putting my code below can anyone please help?



thanks in advance.



try

CommonUtility.LogMessage("Start at:" + DateTime.Now);
string adfsUrl = System.Configuration.ConfigurationManager.AppSettings["ADServer"] ?? "";
if(string.IsNullOrEmpty(adfsUrl))

CommonUtility.LogMessage("no adfs server found in config");
return RedirectToAction("Login", "Account", string.Empty);


string requestUrlScheme = System.Configuration.ConfigurationManager.AppSettings["ADInstance"] ?? "https";
string federationUrl = System.Configuration.ConfigurationManager.AppSettings["ADFSMetaData"] ?? "";

CommonUtility.LogMessage("metdaDataUrl=" + federationUrl);

string trustUrl = string.Format("0/adfs/services/trust", adfsUrl);

CommonUtility.LogMessage("trustURL=" + trustUrl);

var idps = Kentor.AuthServices.Mvc.AuthServicesController.Options.IdentityProviders.KnownIdentityProviders;
foreach (var idpItem in idps)

CommonUtility.LogMessage("existing ENtity ID=" + idpItem.EntityId.Id);
if (idpItem.EntityId.Id.Equals(trustUrl))

Kentor.AuthServices.Mvc.AuthServicesController.Options.IdentityProviders.Remove(idpItem.EntityId);
CommonUtility.LogMessage("removed existing entity at:" + DateTime.Now);



var spOptions = CreateSPOptions(requestUrlScheme);

CommonUtility.LogMessage("SP option created at:" + DateTime.Now);

Kentor.AuthServices.IdentityProvider idp = null;


**idp = new Kentor.AuthServices.IdentityProvider(new EntityId(trustUrl), spOptions)

AllowUnsolicitedAuthnResponse = true,
LoadMetadata = true,
MetadataLocation = federationUrl,

;**
CommonUtility.LogMessage("idp added at:" + DateTime.Now);
if (Kentor.AuthServices.Mvc.AuthServicesController.Options.SPOptions.EntityId == null)
Kentor.AuthServices.Mvc.AuthServicesController.Options.SPOptions.EntityId = new EntityId(string.Concat(string.Format("0://12", requestUrlScheme, Request.Url.Authority, Url.Content("~")), "AuthServices"));
else
Kentor.AuthServices.Mvc.AuthServicesController.Options.SPOptions.EntityId.Id =
string.Concat(string.Format("0://12", requestUrlScheme, Request.Url.Authority, Url.Content("~")), "AuthServices");


CommonUtility.LogMessage("AuthServicesURL=" + string.Concat(string.Format("0://12", requestUrlScheme, Request.Url.Authority, Url.Content("~")), "AuthServices"));

Kentor.AuthServices.Mvc.AuthServicesController.Options.SPOptions.ReturnUrl =
new Uri(string.Concat(string.Format("0://12", requestUrlScheme, Request.Url.Authority, Url.Content("~")), "SAMLAuthentication/SAMLResponse"));

CommonUtility.LogMessage("SAMLResponseURL=" + string.Concat(string.Format("0://12", requestUrlScheme, Request.Url.Authority, Url.Content("~")), "SAMLAuthentication/SAMLResponse"));


Kentor.AuthServices.Mvc.AuthServicesController.Options.IdentityProviders.Add(idp);
CommonUtility.LogMessage("redirect times:" + DateTime.Now);
return RedirectToAction("SignIn", "AuthServices", new idp = trustUrl );


catch (Exception ex)

CommonUtility.LogException(ex);
throw ex;











share|improve this question




























    0















    I am using "Kentor.AuthServices.dll" and "Kentor.AuthServices.Mvc.dll" in my code to allowing Single sign on with ADFS server and it is working fine but the problem is that it is taking around more than 1 min show the adfs login screen.



    I have debugged the code and record the timing and found the all the code working fine but identity provider creating code is taking more than 1 min.



    I am not able to understand why it is taking too much time.



    I am putting my code below can anyone please help?



    thanks in advance.



    try

    CommonUtility.LogMessage("Start at:" + DateTime.Now);
    string adfsUrl = System.Configuration.ConfigurationManager.AppSettings["ADServer"] ?? "";
    if(string.IsNullOrEmpty(adfsUrl))

    CommonUtility.LogMessage("no adfs server found in config");
    return RedirectToAction("Login", "Account", string.Empty);


    string requestUrlScheme = System.Configuration.ConfigurationManager.AppSettings["ADInstance"] ?? "https";
    string federationUrl = System.Configuration.ConfigurationManager.AppSettings["ADFSMetaData"] ?? "";

    CommonUtility.LogMessage("metdaDataUrl=" + federationUrl);

    string trustUrl = string.Format("0/adfs/services/trust", adfsUrl);

    CommonUtility.LogMessage("trustURL=" + trustUrl);

    var idps = Kentor.AuthServices.Mvc.AuthServicesController.Options.IdentityProviders.KnownIdentityProviders;
    foreach (var idpItem in idps)

    CommonUtility.LogMessage("existing ENtity ID=" + idpItem.EntityId.Id);
    if (idpItem.EntityId.Id.Equals(trustUrl))

    Kentor.AuthServices.Mvc.AuthServicesController.Options.IdentityProviders.Remove(idpItem.EntityId);
    CommonUtility.LogMessage("removed existing entity at:" + DateTime.Now);



    var spOptions = CreateSPOptions(requestUrlScheme);

    CommonUtility.LogMessage("SP option created at:" + DateTime.Now);

    Kentor.AuthServices.IdentityProvider idp = null;


    **idp = new Kentor.AuthServices.IdentityProvider(new EntityId(trustUrl), spOptions)

    AllowUnsolicitedAuthnResponse = true,
    LoadMetadata = true,
    MetadataLocation = federationUrl,

    ;**
    CommonUtility.LogMessage("idp added at:" + DateTime.Now);
    if (Kentor.AuthServices.Mvc.AuthServicesController.Options.SPOptions.EntityId == null)
    Kentor.AuthServices.Mvc.AuthServicesController.Options.SPOptions.EntityId = new EntityId(string.Concat(string.Format("0://12", requestUrlScheme, Request.Url.Authority, Url.Content("~")), "AuthServices"));
    else
    Kentor.AuthServices.Mvc.AuthServicesController.Options.SPOptions.EntityId.Id =
    string.Concat(string.Format("0://12", requestUrlScheme, Request.Url.Authority, Url.Content("~")), "AuthServices");


    CommonUtility.LogMessage("AuthServicesURL=" + string.Concat(string.Format("0://12", requestUrlScheme, Request.Url.Authority, Url.Content("~")), "AuthServices"));

    Kentor.AuthServices.Mvc.AuthServicesController.Options.SPOptions.ReturnUrl =
    new Uri(string.Concat(string.Format("0://12", requestUrlScheme, Request.Url.Authority, Url.Content("~")), "SAMLAuthentication/SAMLResponse"));

    CommonUtility.LogMessage("SAMLResponseURL=" + string.Concat(string.Format("0://12", requestUrlScheme, Request.Url.Authority, Url.Content("~")), "SAMLAuthentication/SAMLResponse"));


    Kentor.AuthServices.Mvc.AuthServicesController.Options.IdentityProviders.Add(idp);
    CommonUtility.LogMessage("redirect times:" + DateTime.Now);
    return RedirectToAction("SignIn", "AuthServices", new idp = trustUrl );


    catch (Exception ex)

    CommonUtility.LogException(ex);
    throw ex;











    share|improve this question


























      0












      0








      0








      I am using "Kentor.AuthServices.dll" and "Kentor.AuthServices.Mvc.dll" in my code to allowing Single sign on with ADFS server and it is working fine but the problem is that it is taking around more than 1 min show the adfs login screen.



      I have debugged the code and record the timing and found the all the code working fine but identity provider creating code is taking more than 1 min.



      I am not able to understand why it is taking too much time.



      I am putting my code below can anyone please help?



      thanks in advance.



      try

      CommonUtility.LogMessage("Start at:" + DateTime.Now);
      string adfsUrl = System.Configuration.ConfigurationManager.AppSettings["ADServer"] ?? "";
      if(string.IsNullOrEmpty(adfsUrl))

      CommonUtility.LogMessage("no adfs server found in config");
      return RedirectToAction("Login", "Account", string.Empty);


      string requestUrlScheme = System.Configuration.ConfigurationManager.AppSettings["ADInstance"] ?? "https";
      string federationUrl = System.Configuration.ConfigurationManager.AppSettings["ADFSMetaData"] ?? "";

      CommonUtility.LogMessage("metdaDataUrl=" + federationUrl);

      string trustUrl = string.Format("0/adfs/services/trust", adfsUrl);

      CommonUtility.LogMessage("trustURL=" + trustUrl);

      var idps = Kentor.AuthServices.Mvc.AuthServicesController.Options.IdentityProviders.KnownIdentityProviders;
      foreach (var idpItem in idps)

      CommonUtility.LogMessage("existing ENtity ID=" + idpItem.EntityId.Id);
      if (idpItem.EntityId.Id.Equals(trustUrl))

      Kentor.AuthServices.Mvc.AuthServicesController.Options.IdentityProviders.Remove(idpItem.EntityId);
      CommonUtility.LogMessage("removed existing entity at:" + DateTime.Now);



      var spOptions = CreateSPOptions(requestUrlScheme);

      CommonUtility.LogMessage("SP option created at:" + DateTime.Now);

      Kentor.AuthServices.IdentityProvider idp = null;


      **idp = new Kentor.AuthServices.IdentityProvider(new EntityId(trustUrl), spOptions)

      AllowUnsolicitedAuthnResponse = true,
      LoadMetadata = true,
      MetadataLocation = federationUrl,

      ;**
      CommonUtility.LogMessage("idp added at:" + DateTime.Now);
      if (Kentor.AuthServices.Mvc.AuthServicesController.Options.SPOptions.EntityId == null)
      Kentor.AuthServices.Mvc.AuthServicesController.Options.SPOptions.EntityId = new EntityId(string.Concat(string.Format("0://12", requestUrlScheme, Request.Url.Authority, Url.Content("~")), "AuthServices"));
      else
      Kentor.AuthServices.Mvc.AuthServicesController.Options.SPOptions.EntityId.Id =
      string.Concat(string.Format("0://12", requestUrlScheme, Request.Url.Authority, Url.Content("~")), "AuthServices");


      CommonUtility.LogMessage("AuthServicesURL=" + string.Concat(string.Format("0://12", requestUrlScheme, Request.Url.Authority, Url.Content("~")), "AuthServices"));

      Kentor.AuthServices.Mvc.AuthServicesController.Options.SPOptions.ReturnUrl =
      new Uri(string.Concat(string.Format("0://12", requestUrlScheme, Request.Url.Authority, Url.Content("~")), "SAMLAuthentication/SAMLResponse"));

      CommonUtility.LogMessage("SAMLResponseURL=" + string.Concat(string.Format("0://12", requestUrlScheme, Request.Url.Authority, Url.Content("~")), "SAMLAuthentication/SAMLResponse"));


      Kentor.AuthServices.Mvc.AuthServicesController.Options.IdentityProviders.Add(idp);
      CommonUtility.LogMessage("redirect times:" + DateTime.Now);
      return RedirectToAction("SignIn", "AuthServices", new idp = trustUrl );


      catch (Exception ex)

      CommonUtility.LogException(ex);
      throw ex;











      share|improve this question
















      I am using "Kentor.AuthServices.dll" and "Kentor.AuthServices.Mvc.dll" in my code to allowing Single sign on with ADFS server and it is working fine but the problem is that it is taking around more than 1 min show the adfs login screen.



      I have debugged the code and record the timing and found the all the code working fine but identity provider creating code is taking more than 1 min.



      I am not able to understand why it is taking too much time.



      I am putting my code below can anyone please help?



      thanks in advance.



      try

      CommonUtility.LogMessage("Start at:" + DateTime.Now);
      string adfsUrl = System.Configuration.ConfigurationManager.AppSettings["ADServer"] ?? "";
      if(string.IsNullOrEmpty(adfsUrl))

      CommonUtility.LogMessage("no adfs server found in config");
      return RedirectToAction("Login", "Account", string.Empty);


      string requestUrlScheme = System.Configuration.ConfigurationManager.AppSettings["ADInstance"] ?? "https";
      string federationUrl = System.Configuration.ConfigurationManager.AppSettings["ADFSMetaData"] ?? "";

      CommonUtility.LogMessage("metdaDataUrl=" + federationUrl);

      string trustUrl = string.Format("0/adfs/services/trust", adfsUrl);

      CommonUtility.LogMessage("trustURL=" + trustUrl);

      var idps = Kentor.AuthServices.Mvc.AuthServicesController.Options.IdentityProviders.KnownIdentityProviders;
      foreach (var idpItem in idps)

      CommonUtility.LogMessage("existing ENtity ID=" + idpItem.EntityId.Id);
      if (idpItem.EntityId.Id.Equals(trustUrl))

      Kentor.AuthServices.Mvc.AuthServicesController.Options.IdentityProviders.Remove(idpItem.EntityId);
      CommonUtility.LogMessage("removed existing entity at:" + DateTime.Now);



      var spOptions = CreateSPOptions(requestUrlScheme);

      CommonUtility.LogMessage("SP option created at:" + DateTime.Now);

      Kentor.AuthServices.IdentityProvider idp = null;


      **idp = new Kentor.AuthServices.IdentityProvider(new EntityId(trustUrl), spOptions)

      AllowUnsolicitedAuthnResponse = true,
      LoadMetadata = true,
      MetadataLocation = federationUrl,

      ;**
      CommonUtility.LogMessage("idp added at:" + DateTime.Now);
      if (Kentor.AuthServices.Mvc.AuthServicesController.Options.SPOptions.EntityId == null)
      Kentor.AuthServices.Mvc.AuthServicesController.Options.SPOptions.EntityId = new EntityId(string.Concat(string.Format("0://12", requestUrlScheme, Request.Url.Authority, Url.Content("~")), "AuthServices"));
      else
      Kentor.AuthServices.Mvc.AuthServicesController.Options.SPOptions.EntityId.Id =
      string.Concat(string.Format("0://12", requestUrlScheme, Request.Url.Authority, Url.Content("~")), "AuthServices");


      CommonUtility.LogMessage("AuthServicesURL=" + string.Concat(string.Format("0://12", requestUrlScheme, Request.Url.Authority, Url.Content("~")), "AuthServices"));

      Kentor.AuthServices.Mvc.AuthServicesController.Options.SPOptions.ReturnUrl =
      new Uri(string.Concat(string.Format("0://12", requestUrlScheme, Request.Url.Authority, Url.Content("~")), "SAMLAuthentication/SAMLResponse"));

      CommonUtility.LogMessage("SAMLResponseURL=" + string.Concat(string.Format("0://12", requestUrlScheme, Request.Url.Authority, Url.Content("~")), "SAMLAuthentication/SAMLResponse"));


      Kentor.AuthServices.Mvc.AuthServicesController.Options.IdentityProviders.Add(idp);
      CommonUtility.LogMessage("redirect times:" + DateTime.Now);
      return RedirectToAction("SignIn", "AuthServices", new idp = trustUrl );


      catch (Exception ex)

      CommonUtility.LogException(ex);
      throw ex;








      c# saml-2.0 adfs kentor-authservices sustainsys-saml2






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 10:51









      Anders Abel

      56.9k10123198




      56.9k10123198










      asked Nov 14 '18 at 10:19









      IrfanIrfan

      1




      1






















          1 Answer
          1






          active

          oldest

          votes


















          0














          When you use "LoadMetadata", the IdentityProvider object will load the metadata from the remote address at construction time. If I remember correctly, that's done synchronously to be able to report errors back as an exception. Does it take time (or give a timeout) to download the metadata?






          share|improve this answer























          • Thanks, @Anders for your reply. if I download the metadata from remote location in the browser it will not take more than 2-3 seconds. but in the code, it takes more than 1 min to complete the new idp creation. I have also tried to use the metadata file from the local folder(downloaded metadata). but it is taking the same time as it takes with a remote location. Thanks

            – Irfan
            Nov 15 '18 at 3:09











          • Looks like some debugging is needed. Can you please mail me the metadata file at anders@sustainsys.com?

            – Anders Abel
            Nov 15 '18 at 8:48











          • I have sent you the metadata file. please let me the problem. Thanks!

            – Irfan
            Nov 16 '18 at 5:11










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53297841%2fsaml-idp-creation-taking-too-much-time%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          When you use "LoadMetadata", the IdentityProvider object will load the metadata from the remote address at construction time. If I remember correctly, that's done synchronously to be able to report errors back as an exception. Does it take time (or give a timeout) to download the metadata?






          share|improve this answer























          • Thanks, @Anders for your reply. if I download the metadata from remote location in the browser it will not take more than 2-3 seconds. but in the code, it takes more than 1 min to complete the new idp creation. I have also tried to use the metadata file from the local folder(downloaded metadata). but it is taking the same time as it takes with a remote location. Thanks

            – Irfan
            Nov 15 '18 at 3:09











          • Looks like some debugging is needed. Can you please mail me the metadata file at anders@sustainsys.com?

            – Anders Abel
            Nov 15 '18 at 8:48











          • I have sent you the metadata file. please let me the problem. Thanks!

            – Irfan
            Nov 16 '18 at 5:11















          0














          When you use "LoadMetadata", the IdentityProvider object will load the metadata from the remote address at construction time. If I remember correctly, that's done synchronously to be able to report errors back as an exception. Does it take time (or give a timeout) to download the metadata?






          share|improve this answer























          • Thanks, @Anders for your reply. if I download the metadata from remote location in the browser it will not take more than 2-3 seconds. but in the code, it takes more than 1 min to complete the new idp creation. I have also tried to use the metadata file from the local folder(downloaded metadata). but it is taking the same time as it takes with a remote location. Thanks

            – Irfan
            Nov 15 '18 at 3:09











          • Looks like some debugging is needed. Can you please mail me the metadata file at anders@sustainsys.com?

            – Anders Abel
            Nov 15 '18 at 8:48











          • I have sent you the metadata file. please let me the problem. Thanks!

            – Irfan
            Nov 16 '18 at 5:11













          0












          0








          0







          When you use "LoadMetadata", the IdentityProvider object will load the metadata from the remote address at construction time. If I remember correctly, that's done synchronously to be able to report errors back as an exception. Does it take time (or give a timeout) to download the metadata?






          share|improve this answer













          When you use "LoadMetadata", the IdentityProvider object will load the metadata from the remote address at construction time. If I remember correctly, that's done synchronously to be able to report errors back as an exception. Does it take time (or give a timeout) to download the metadata?







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 '18 at 18:40









          Anders AbelAnders Abel

          56.9k10123198




          56.9k10123198












          • Thanks, @Anders for your reply. if I download the metadata from remote location in the browser it will not take more than 2-3 seconds. but in the code, it takes more than 1 min to complete the new idp creation. I have also tried to use the metadata file from the local folder(downloaded metadata). but it is taking the same time as it takes with a remote location. Thanks

            – Irfan
            Nov 15 '18 at 3:09











          • Looks like some debugging is needed. Can you please mail me the metadata file at anders@sustainsys.com?

            – Anders Abel
            Nov 15 '18 at 8:48











          • I have sent you the metadata file. please let me the problem. Thanks!

            – Irfan
            Nov 16 '18 at 5:11

















          • Thanks, @Anders for your reply. if I download the metadata from remote location in the browser it will not take more than 2-3 seconds. but in the code, it takes more than 1 min to complete the new idp creation. I have also tried to use the metadata file from the local folder(downloaded metadata). but it is taking the same time as it takes with a remote location. Thanks

            – Irfan
            Nov 15 '18 at 3:09











          • Looks like some debugging is needed. Can you please mail me the metadata file at anders@sustainsys.com?

            – Anders Abel
            Nov 15 '18 at 8:48











          • I have sent you the metadata file. please let me the problem. Thanks!

            – Irfan
            Nov 16 '18 at 5:11
















          Thanks, @Anders for your reply. if I download the metadata from remote location in the browser it will not take more than 2-3 seconds. but in the code, it takes more than 1 min to complete the new idp creation. I have also tried to use the metadata file from the local folder(downloaded metadata). but it is taking the same time as it takes with a remote location. Thanks

          – Irfan
          Nov 15 '18 at 3:09





          Thanks, @Anders for your reply. if I download the metadata from remote location in the browser it will not take more than 2-3 seconds. but in the code, it takes more than 1 min to complete the new idp creation. I have also tried to use the metadata file from the local folder(downloaded metadata). but it is taking the same time as it takes with a remote location. Thanks

          – Irfan
          Nov 15 '18 at 3:09













          Looks like some debugging is needed. Can you please mail me the metadata file at anders@sustainsys.com?

          – Anders Abel
          Nov 15 '18 at 8:48





          Looks like some debugging is needed. Can you please mail me the metadata file at anders@sustainsys.com?

          – Anders Abel
          Nov 15 '18 at 8:48













          I have sent you the metadata file. please let me the problem. Thanks!

          – Irfan
          Nov 16 '18 at 5:11





          I have sent you the metadata file. please let me the problem. Thanks!

          – Irfan
          Nov 16 '18 at 5:11



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53297841%2fsaml-idp-creation-taking-too-much-time%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

          Syphilis

          Darth Vader #20