Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. c# WebBrowser returns unauthorized for different domain users

c# WebBrowser returns unauthorized for different domain users

Scheduled Pinned Locked Moved C#
csharpcomhelp
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kubiiik
    wrote on last edited by
    #1

    Hi. I'm using WebBrowser to display authenticated web page. I implemented the interfaces decribed in this post.

    object obj = myBrowser.ActiveXInstance;
    IOleObject oc = obj as IOleObject;
    oc.SetClientSite(this as IOleClientSite);

    string authHeader = "WWW-Authenticate: Negotiate\r\n";
    myBrowser.Navigate(_URL, "", null, authHeader);

    I'm using Negotiate so I can use also SSO. The authenticate method is implemented like this:

    public int Authenticate(ref IntPtr phwnd, ref IntPtr pszUsername, ref IntPtr pszPassword)
    {
    pszUsername = Marshal.StringToCoTaskMemAuto("user");
    pszPassword = Marshal.StringToCoTaskMemAuto("pass");
    return S_OK;
    }

    It works well. But the problem is when I want to authenticate the user with different domain. This doesn't work:

    pszUsername = Marshal.StringToCoTaskMemAuto(@"domain\user");
    pszUsername = Marshal.StringToCoTaskMemAuto("user@domain");

    I'm not able to display the page for users with different domains. It returns unauthorized. I don't know what changes to make so it's working.. Thank you.

    L 1 Reply Last reply
    0
    • K kubiiik

      Hi. I'm using WebBrowser to display authenticated web page. I implemented the interfaces decribed in this post.

      object obj = myBrowser.ActiveXInstance;
      IOleObject oc = obj as IOleObject;
      oc.SetClientSite(this as IOleClientSite);

      string authHeader = "WWW-Authenticate: Negotiate\r\n";
      myBrowser.Navigate(_URL, "", null, authHeader);

      I'm using Negotiate so I can use also SSO. The authenticate method is implemented like this:

      public int Authenticate(ref IntPtr phwnd, ref IntPtr pszUsername, ref IntPtr pszPassword)
      {
      pszUsername = Marshal.StringToCoTaskMemAuto("user");
      pszPassword = Marshal.StringToCoTaskMemAuto("pass");
      return S_OK;
      }

      It works well. But the problem is when I want to authenticate the user with different domain. This doesn't work:

      pszUsername = Marshal.StringToCoTaskMemAuto(@"domain\user");
      pszUsername = Marshal.StringToCoTaskMemAuto("user@domain");

      I'm not able to display the page for users with different domains. It returns unauthorized. I don't know what changes to make so it's working.. Thank you.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Forget about the code for a second; can you give us an example of which domain you would like to authenticate? See, if you're authenticating someone from, say, Microsoft, then their domain-server would have to trust[^] yours. The network-name might not always the same as the domain that is used on the internet.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

      K 1 Reply Last reply
      0
      • L Lost User

        Forget about the code for a second; can you give us an example of which domain you would like to authenticate? See, if you're authenticating someone from, say, Microsoft, then their domain-server would have to trust[^] yours. The network-name might not always the same as the domain that is used on the internet.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

        K Offline
        K Offline
        kubiiik
        wrote on last edited by
        #3

        The app I'm connecting to, runs on our server. There is also web login to the server app. The users log in using domain with their username (domain\user1). I'm not very familiar with this technology but I will look up necessary facts, if you need more info.

        L 1 Reply Last reply
        0
        • K kubiiik

          The app I'm connecting to, runs on our server. There is also web login to the server app. The users log in using domain with their username (domain\user1). I'm not very familiar with this technology but I will look up necessary facts, if you need more info.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          ..so, the user opens a webpage on your webserver, logs in using a form? Can the user login using those credentials using a regular browser?

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

          K 1 Reply Last reply
          0
          • L Lost User

            ..so, the user opens a webpage on your webserver, logs in using a form? Can the user login using those credentials using a regular browser?

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

            K Offline
            K Offline
            kubiiik
            wrote on last edited by
            #5

            Yes, the user can log in using the form on webpage with the given credentials. In the web form the user selects the domain, put down the username and password. As I was told the domain and the username are then put together like this "domain\username" when the logging is being processed. That led me to conclusion that I should concatenate the domain and the username in the winforms app too. But I'm getting unauthorised. So I thought that there is something else I should set..

            L 1 Reply Last reply
            0
            • K kubiiik

              Yes, the user can log in using the form on webpage with the given credentials. In the web form the user selects the domain, put down the username and password. As I was told the domain and the username are then put together like this "domain\username" when the logging is being processed. That led me to conclusion that I should concatenate the domain and the username in the winforms app too. But I'm getting unauthorised. So I thought that there is something else I should set..

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              kubiiik wrote:

              So I thought that there is something else I should set..

              You should be able to sign in on your own website without modifications. The WebBrowser-control is "just" an instance of IE, nothing special. The thing that threw me off was the reference to "other domains". You wouldn't be able to authenticate people from the domain our company uses, simply because it is outside the network.

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

              K 1 Reply Last reply
              0
              • L Lost User

                kubiiik wrote:

                So I thought that there is something else I should set..

                You should be able to sign in on your own website without modifications. The WebBrowser-control is "just" an instance of IE, nothing special. The thing that threw me off was the reference to "other domains". You wouldn't be able to authenticate people from the domain our company uses, simply because it is outside the network.

                Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                K Offline
                K Offline
                kubiiik
                wrote on last edited by
                #7

                Eddy Vluggen wrote:

                You should be able to sign in on your own website without modifications. The WebBrowser-control is "just" an instance of IE, nothing special.

                Just to clarify, we do not display any login page in the webBrowser. If the user log in using regular browser, the log in page is displayed. But when using the C# winforms app, the log in is set in the app and used as string in the Authenticate method.

                Eddy Vluggen wrote:

                The thing that threw me off was the reference to "other domains". You wouldn't be able to authenticate people from the domain our company uses, simply because it is outside the network.

                I don't understand the domain users much (I had to google more info about it), but I think that the domain controller should handle the users (according to http://www.howtogeek.com/194069/what-is-a-windows-domain-and-how-does-it-affect-my-pc/[^]).

                L 1 Reply Last reply
                0
                • K kubiiik

                  Eddy Vluggen wrote:

                  You should be able to sign in on your own website without modifications. The WebBrowser-control is "just" an instance of IE, nothing special.

                  Just to clarify, we do not display any login page in the webBrowser. If the user log in using regular browser, the log in page is displayed. But when using the C# winforms app, the log in is set in the app and used as string in the Authenticate method.

                  Eddy Vluggen wrote:

                  The thing that threw me off was the reference to "other domains". You wouldn't be able to authenticate people from the domain our company uses, simply because it is outside the network.

                  I don't understand the domain users much (I had to google more info about it), but I think that the domain controller should handle the users (according to http://www.howtogeek.com/194069/what-is-a-windows-domain-and-how-does-it-affect-my-pc/[^]).

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  kubiiik wrote:

                  Just to clarify, we do not display any login page in the webBrowser. If the user log in using regular browser, the log in page is displayed. But when using the C# winforms app, the log in is set in the app and used as string in the Authenticate method.

                  Thanks for that clarification :) I was expecting windows-authentication, which would not require a special login.

                  kubiiik wrote:

                  I don't understand the domain users much (I had to google more info about it), but I think that the domain controller should handle the users

                  Yes, but you won't be able to verify anyone outside your own domain.

                  Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                  K 1 Reply Last reply
                  0
                  • L Lost User

                    kubiiik wrote:

                    Just to clarify, we do not display any login page in the webBrowser. If the user log in using regular browser, the log in page is displayed. But when using the C# winforms app, the log in is set in the app and used as string in the Authenticate method.

                    Thanks for that clarification :) I was expecting windows-authentication, which would not require a special login.

                    kubiiik wrote:

                    I don't understand the domain users much (I had to google more info about it), but I think that the domain controller should handle the users

                    Yes, but you won't be able to verify anyone outside your own domain.

                    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                    K Offline
                    K Offline
                    kubiiik
                    wrote on last edited by
                    #9

                    According to the new information I got, the server end has only implemented WindowsBasicAuthenticator, which ignores these domains. But unless the server end implementation is updated, I will not know that for sure. Anyway, thank you for your time :)

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups