Making WebRequest in plugin using Network credential RRS feed

  • Question

  • Hi All,

    I am making a web request in my plugin ,it is working fine . But it is making two web request, I've looked on server trace I found two web request one with status code 200 and other one with status code 401.

    Does anybody have idea why this is making two calls and how can I resolve this? I want to make only one call with status 200.

    I am using below code to make a web request. My plugin is registered on Create of any entity as Post operation, and it is asynchronous.

    NetworkCredential nwCred=new NetworkCredential();
                nwCred.UserName = Username;
                nwCred.Domain = Domain;
                nwCred.Password = Password;
                WebRequest request = WebRequest.Create(uri);
                request.Method = "POST";
                request.ContentType = "application/json";
                request.Credentials = nwCred;
                using (Stream stream = request.GetRequestStream())
                    using (StreamWriter writer = new StreamWriter(stream))

    Thanks ,

    Friday, July 19, 2013 11:59 AM

All replies

  • Can you please check and debug if  your  plugin is  not  firing twice?


    Friday, July 19, 2013 2:03 PM
  • Hi Kar Pallavi,

    thank you for your reply.

    no,this plugin is not getting fire twice.I think there is some problem with web request.


    Wednesday, July 24, 2013 5:41 AM
  • I think this is standard HTTP behaviour; the request will first try without credentials (generating a 401), then submit the credentials. Using PreAuthenticate = true will stop the 401 on subsequent calls, but I think you will still get the 401 on the first call - see http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.preauthenticate(v=VS.85).aspx

    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Wednesday, July 24, 2013 9:10 AM