System.Net.CredentialCache.DefaultCredentials returns an empty string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ckb
    New Member
    • Sep 2007
    • 17

    System.Net.CredentialCache.DefaultCredentials returns an empty string

    Hi,
    I have an active x ctrl on my page and using asp.net I i have built a web page that has a web service named e1.I am using CreateSessionIm personated()
    but it does not Impersonate and every time asks for the user name and the password.The code is
    e1.Url = "http://Servername/VServer/WebService.asmx "
    e1.Credentials = System.Net.Cred entialCache.Def aultCredentials
    ControlPlaceHol der = Me.FindControl( "PlaceHolde r1")
    ControlPlaceHol der.Controls.Cl ear()
    If Session("sessio nID") = "" Then
    SessionHeader = e1.CreateSessio nImpersonated(s trProvider, "", "", "", "")
    Session("sessio nID") = SessionHeader.I D
    End If
    Can anybody help me on this please.
    Thankyou.
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Are you sure its CreateSessionIm personated? I've only seen this used in Java.

    Comment

    • ckb
      New Member
      • Sep 2007
      • 17

      #3
      No it is CreateSessionIm personated()

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Can you just look in the request header and rip out the authenticate header?
        I've never had good luck with the CredentialCache , I always just resorted to building the base64 string myself. Way easier.

        Althought for https I dunno if it works

        Comment

        • ckb
          New Member
          • Sep 2007
          • 17

          #5
          Nothing works .Can anybody help me on this.

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            You're looking to access a service with the same supplied credentials as was sent to your page right?

            Like someone authenticates with you then you use that same auth and use it to connect to webservice(or something) right?

            Comment

            • ckb
              New Member
              • Sep 2007
              • 17

              #7
              I am trying to use the windows credentials(Int rgrated Login) to get connected to my webservice

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                And you have it setup correctly in your web.config?

                Comment

                • ckb
                  New Member
                  • Sep 2007
                  • 17

                  #9
                  My web config has identity impersonate to true and
                  authentication mode is set to windows but default credentials is still returns an empty sting and hence it passes the empoty string to the createsessionim personate function.Any help on this.
                  tHANKYOU

                  Comment

                  • Plater
                    Recognized Expert Expert
                    • Apr 2007
                    • 7872

                    #10
                    So you have a section in web.config like:

                    [code=xml]
                    <authenticati on mode="Windows">
                    <forms loginUrl="Admin/Adminlogin.aspx " name=".ASPXFORM SAUTH" defaultUrl="Adm in/AdminFunctions. aspx" path="/Admin" timeout="10" slidingExpirati on="true">
                    <credentials passwordFormat= "Clear">
                    </credentials>
                    </forms>
                    </authentication>
                    <location path="Admin">
                    <system.web>
                    <identity impersonate="fa lse"/>
                    <!-- WS: Allow only Authenticated users -->
                    <authorizatio n>
                    <!-- allow users="*"/ -->
                    <deny users="?"/>
                    </authorization>
                    </system.web>
                    </location>
                    [/code]

                    And then you have a login place (in case they aren't validated automatically) such as ""
                    Where there's two texboxes and a button with a click handler that does:
                    Code:
                    string aUser = "";
                    string aPass = "";
                    bool allowedtoenter=false;
                    aUser = UserName.Text;
                    aPass = UserPass.Text;
                    allowedtoenter= FormsAuthentication.Authenticate(aUser, aPass);
                    if (allowedtoenter)
                    {//
                       FormsAuthentication.RedirectFromLoginPage(UserName.Text, false);
                    }

                    Comment

                    • ckb
                      New Member
                      • Sep 2007
                      • 17

                      #11
                      No i want it to take the default windows login ie my the password that i use to login to my machine.So my congig file just has
                      ?xml version="1.0"?>
                      <!--
                      Note: As an alternative to hand editing this file you can use the
                      web admin tool to configure settings for your application. Use
                      the Website->Asp.Net Configuration option in Visual Studio.
                      A full list of settings and comments can be found in
                      machine.config. comments usually located in
                      \Windows\Micros oft.Net\Framewo rk\v2.x\Config
                      -->
                      <configuratio n>
                      <appSettings>
                      <add key="Ev_WebSevi ce_Assigned_Web .WebService" value="http://ukrdgap349/evserver/WebService.asmx "/>
                      </appSettings>
                      <connectionStri ngs/>
                      <!--for impersonation-->
                      <system.web>

                      <identity impersonate="tr ue" />
                      <!-- userName="domai n/username"
                      password="passw ord" />-->


                      <!--
                      Set compilation debug="true" to insert debugging
                      symbols into the compiled page. Because this
                      affects performance, set this value to true only
                      during development.

                      Visual Basic options:
                      Set strict="true" to disallow all data type conversions
                      where data loss can occur.
                      Set explicit="true" to force declaration of all variables.
                      -->
                      <compilation debug="true" strict="false" explicit="true"/>
                      <pages>
                      <namespaces>
                      <clear/>
                      <add namespace="Syst em"/>
                      <add namespace="Syst em.Collections"/>
                      <add namespace="Syst em.Collections. Specialized"/>
                      <add namespace="Syst em.Configuratio n"/>
                      <add namespace="Syst em.Text"/>
                      <add namespace="Syst em.Text.Regular Expressions"/>
                      <add namespace="Syst em.Web"/>
                      <add namespace="Syst em.Web.Caching"/>
                      <add namespace="Syst em.Web.SessionS tate"/>
                      <add namespace="Syst em.Web.Security "/>
                      <add namespace="Syst em.Web.Profile"/>
                      <add namespace="Syst em.Web.UI"/>
                      <add namespace="Syst em.Web.UI.WebCo ntrols"/>
                      <add namespace="Syst em.Web.UI.WebCo ntrols.WebParts "/>
                      <add namespace="Syst em.Web.UI.HtmlC ontrols"/>
                      <add namespace="Syst em.Net"/>
                      </namespaces>
                      </pages>
                      <!--
                      The <authentication > section enables configuration
                      of the security authentication mode used by
                      ASP.NET to identify an incoming user.
                      -->
                      <authenticati on mode="Windows" />

                      <!--
                      The <customErrors > section enables configuration
                      of what to do if/when an unhandled error occurs
                      during the execution of a request. Specifically,
                      it enables developers to configure html error pages
                      to be displayed in place of a error stack trace.

                      <customErrors mode="RemoteOnl y" defaultRedirect ="GenericErrorP age.htm">
                      <error statusCode="403 " redirect="NoAcc ess.htm" />
                      <error statusCode="404 " redirect="FileN otFound.htm" />
                      </customErrors>
                      -->
                      </system.web>
                      </configuration>
                      I do not have any separate login screen that checks what type of login it is .It is just that when i open a page from a link ,to view my active x ctrl i should not have to login.

                      Comment

                      • Plater
                        Recognized Expert Expert
                        • Apr 2007
                        • 7872

                        #12
                        Originally posted by ckb
                        No i want it to take the default windows login ie my the password that i use to login to my machine.So my congig file just has


                        I do not have any separate login screen that checks what type of login it is .It is just that when i open a page from a link ,to view my active x ctrl i should not have to login.
                        Right.
                        But the system won't supply the credentials unless you have a:
                        [code=xml]
                        <authorizatio n>
                        <!-- allow users="*"/ -->
                        <deny users="?"/>
                        </authorization>
                        [/code]
                        that will force it to.

                        In my example I only had it require "windows" credentials for the "Admin/*" section, so you might have missed the authentication part.
                        I believe you can use wildcards in the <location> section to force it for only a single page.

                        The reason I had the other stuff is because your credentials aren't always readily available (if you load the page from a computer outside the network or from a different unmanaged-domain) and needed a way to specify them

                        Comment

                        Working...