1

We run our intranet site with PHP on an iSeries with Apache. By default, PHP hosted on this box can not automatically get the username of the logged on windows user.

With asp.net pages hosted from a windows server, we can automatically get that username.

From a PHP page, call it login.php, i want to (through whatever method), call or redirect the user to an asp.net webpage hosted on a different server. This asp.net page will pass back a value (the username).

I know the syntax for retrieving the username from .net. But, what I dont want to do, is a URL redirect back to login.php with a querystring example of ?username=bob ... because it is directly visible to the users and has many obvious flaws.

How can I go about achieving this? Maybe using Ajax? Or some sort of .net code for example Request.LastUrlVisited.ReturnValue("bob"), which doesnt show in the URL bar?

I believe the asp.net page needs to specifically be a webpage, as a asp.net webservice can not retieve the username from windows.

Thanks,


Update

Through the comments, i've come to understand that an asp.net webservice CAN in fact get the username.. it does not need to be a webpage. So this opens up a bunch of possibilities to call the webservice service from php.

adam
  • 2,930
  • 7
  • 54
  • 89
  • What kind of .Net application is it? A Web Page or Web Service? MVC or Web Forms? – Liam Mar 14 '12 at 13:25
  • the PHP page is a web page. the asp.net page is likely also a webpage because i dont believe a webservice can retrieve the windows usernames. i'll update my post with this detail as well. – adam Mar 14 '12 at 13:26
  • instead of trying to get username from other application why not try with php? check this post if this helps you - http://stackoverflow.com/questions/168610/can-you-get-a-windows-ad-username-in-php – rs. Mar 14 '12 at 13:28
  • that only works when PHP is hosted from various other server(s). An iSeries with Apache can not do this without installing a mod such as "Mod_auth_kerb" onto the iSeries. While this is an option, it is the very last resort. – adam Mar 14 '12 at 13:31
  • Do not have access to the .Net site then? I.e. you can't modify this? – Liam Mar 14 '12 at 13:33
  • I do have access to the .net site, and I can make any modifications to it that are necessary. I apologize if I dont understand the question correctly. – adam Mar 14 '12 at 13:34
  • 1
    ok why not create a asp.net webservice and do a json/webservice call to asp.net webservice and get username and you can check this - http://stackoverflow.com/questions/2665223/get-username-from-webservice – rs. Mar 14 '12 at 13:37
  • Sorry to ask so many questions but, Is there an option to convert your .Net site to a web service? Becuase your not actually after the site to render any data, it's only providing a service for you. It makes more sense to run this as a WebService? – Liam Mar 14 '12 at 13:38
  • this sounds reasonable. Although I'm not familiar with json. I just tried that code on a webservice in debug from my local and it worked.. can you post this as an answer with details about the whole json thing? Just made an update to my OP. – adam Mar 14 '12 at 13:41

2 Answers2

2

ok why not create a asp.net webservice and do a json/webservice call to asp.net webservice and get username and you can check this - get username from Webservice

Code:

Context.Request.ServerVariables["LOGON_USER"]
Community
  • 1
  • 1
rs.
  • 26,707
  • 12
  • 68
  • 90
2

Ok, I'm making the presumption that you can convert your .Net site to a web service. This will look something like this:

[WebMethod]
        public string GetUserName()
        {

        }

You can then call this webservice form JQuery:

  $.ajax({
    type: "POST",
    url: "blah.asmx/GetUserName",
    data: "{}",
    dataType: "text",
    success: function(username) {
      //do stuff
    }
  });

HEre's a site with a better explanation:

http://encosia.com/using-jquery-to-consume-aspnet-json-web-services/

EDIT

I would encrypt the username too

Liam
  • 27,717
  • 28
  • 128
  • 190