NetworkCred and byref - Bug or by design??

Discussion in 'ASP .Net Security' started by Mark Harris, Jan 21, 2004.

  1. Mark Harris

    Mark Harris Guest

    Hi all

    Have spent an annoying afternoon with this problem, and am wondering if anyone else has come accross it or whether it's known about.

    Scenario is, i have NetworkCred object in one function, it get's passed BYREF to a function in another object ... which runs off to the registry to get the (encrypted) UID and Password. This function then decrpyts the UID / PWD, sets the properties on the NetwordCred object, and returns to the starting function. However, if i then try to use this NC object on a Web Service Proxy, i get a 401 Access Denied from my "Windows Auth"'ed webservice.
    Note : When u check the username and Password properties of the NC object in the main function, they are saturated with the correct values.

    However, if i dont call the external function that goes to the registry, and C&P it's code into the main function (ie. No need to pass the NC object byref!) and use the NC object on the Proxy, it runs the call perfectly well with no annoying 401's!!

    eg.
    'get login credentials for the webservice
    objBroker = New DatabrokerServices.DatabrokerService 'the web service proxy
    objUtil.GetServiceURL(mstrSERVICE_DATABROKER, strURL)
    objBroker.Url = strURL

    objCred = New System.Net.NetworkCredential
    blnReturn = objUtil.GetServiceCredentials(mstrSERVICE_DATABROKER, objCred)
    objBroker.Credentials = objCred.GetCredential(New Uri(strURL), "Negotiate")

    strResponseEnc = objBroker.Execute(strCommandEnc) ' Fails with a 401, uid / pwd properties have correct values

    ********
    whereas, this code works fine ... and yet it's looking at the same registry settings!?

    objCred = New System.Net.NetworkCredential
    objCred.Username = objUtil.GetServiceUID(mstrSERVICE_DATABROKER)
    objCred.Password = objUtil.GetServicePWD(mstrSERVICE_DATABROKER)
    objBroker.Credentials = objCred.GetCredential(New Uri(strURL), "Negotiate")

    strResponseEnc = objBroker.Execute(strCommandEnc)

    **************************************

    Explanations anyone??

    Cheers


    Mark
    Mark Harris, Jan 21, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Goncalo

    ByVal and ByRef

    Goncalo, Dec 4, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    6,050
    Dmitriy Lapshin [C# / .NET MVP]
    Dec 4, 2003
  2. Alex Brown

    StateServer pass byref threading problem

    Alex Brown, Apr 21, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    321
    Alex Brown
    Apr 22, 2004
  3. Iams

    Byval vs. byref

    Iams, Feb 24, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    4,781
  4. xamman
    Replies:
    1
    Views:
    337
    Marina Levit [MVP]
    Dec 22, 2006
  5. Rob Meade

    Byref / Byval?

    Rob Meade, Dec 28, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    748
    Rob Meade
    Dec 28, 2006
Loading...

Share This Page