views:

82

answers:

3

I have a site which is built in ASP.net and C#. Let's call it webapp. it uses a Form system to log on into it, and cannot be changed easliy.

I got a request to change the log in to some kind of windows authentication. I'll explain. Our windows login uses active directory for users to log into their windows account. their login name is sXXXXXXX. X are numbers. in my webapp, I want to take the users numbers from their active directory login, and check if those exist in the webapp database. if it exists, they will automatically log in. If it doesn't, they will be referred to the regular login page for the webapp system which is currently in use.

I tried changing my IIS to disable anonymous login and enabling windows authentication, therefore making the user browser to send it's current logged in user name to my webapp. I changed the web config as well from "Forms" to "Windows", which made my whole webapp obsolete as the whole forms system did not work.

My question is this - is there a different way for the browser only to send the username to my webapp? I thought maybe javascript, I just don't know how to implement that, if it's even possible. I know it's not very secure, but all this platform and system is built outside the internet, it's on a private network.

+1  A: 

The only way you could get at the user's domain credentials via javascript would be by deploying some type of ActiveX component to expose that data to the browser. I wouldn't recommend that.

I would look at implementing a Login page for forms authentication that authenticates the user on the page load using HttpContext.Current.User.

The way forms works is that if an unauthenticated user attempts to access an access-controlled page and have not logged in (no cookie), they will be redirected to a login page that gives the facility to log in (this sets a cookie on the client-side). The user is then directed to the page they initially requested. You would simply be automating the login part.

If you have a mixture of pass-through and user who need to manually login you could check their client IP address to see if it matches one on your domain or not.

David Neale
The current system does exactly what you said - the user authenticates in the login page, which sets the cookie on the client side.When I tried enabling Windows Authentication, both on IIS and on the web.config, my site just would not work - the whole login form, and site actually, is based around Forms authentication mode in the web.config - I cannot change that as my site would just not work.I know ActiveX is not secure and is not recommended, but I just can't see another way... if there is i'd be happy to know. If not, I'd like to get an explanation of how to implement the ActiveX.
jbkkd
There's a handy tutorial here: http://dotnetslackers.com/articles/csharp/writinganactivexcontrolincsharp.aspx. But I can't help but think there's an obvious way around this. I just can't think of it yet!
David Neale
+1  A: 
<script language="javascript">
    var username = '<%HttpContext.Current.User.Identity.Name %>';

</script>
Boris Modylevsky
This would only work if Windows Authentication was enabled. The user cannot do this.
David Neale
A: 

The solution I found for getting the username sent to the server was:

string winlogon = Request.ServerVariables["LOGON_USER"];

After enabled Windows Authentication Mode in IIS.

jbkkd