views:

781

answers:

5

I have an (ASP.NET 3.5) intranet application which has been designed to use forms authentication (along with the default aspnet membership system). I also store additional information about users in another table which shares its primary key with the aspnet_users table.

For users who are part of our domain I store their domain account name in the secondary users table, and I want to automatically log in users whose domain account name matches a name stored in the table.

I have read the guides which are available - they're all from two years ago or more and assume that you are able to activate Windows Authentication on a separate login page that allows you to extract the domain account name. From what I can tell, though, this is not possible in IIS7 (the overall authentication method is applied on all pages and cannot be selectively deactivated, and both authentication methods can't be applied on the same page).

Is there a way of getting IIS to pass through the windows domain account name of the requesting user? I don't need proper AD authentication, just the domain name.

A: 

I've got something you can try - not sure if it will work.

In the past we've used Request.ServerVariables["LOGON_USER"] but obviously for this to return a non-empty value you need to disable Anonymous access.

See this article: http://support.microsoft.com/default.aspx/kb/306359

It suggests keeping Anonymous access on the IIS side, and Forms authentication, but denying the anonymous user as follows:

<authorization> <deny users = "?" /> <!-- This denies access to the Anonymous user --> <allow users ="*" /> <!-- This allows access to all users --> </authorization>

Not sure if this will work but worth a try.

-Krip

Krip
Thanks - gave it a try but it's still an empty string even with the settings as recommended.I doudble checked the article and it doesn't apply to IIS7, unfortunately.
dr_draik
A: 

Unfortunately, what you are trying to do just isn't supported. In order for ASP.NET to know the Windows username, you must use Windows Authentication.

You could set up another site / virtual directory that just forwarded the username information to another page. But what happens when non-Windows authenticated users try to log in?

Bryan
Thanks, the two application solution seems the most workable, but I reckon we'll just have to go with forms auth. It feels rather clumsy to have a separate app just for the login.
dr_draik
A: 

You could always set up 2 separate application in IIS7. One would have Windows Authentication enabled. The other would be the main app with forms authentication. If a user went to the windows authentication app, the page could grab their credentials and pass it to the forms authentication app.

David
Thanks, the two application solution seems the most workable, but I reckon we'll just have to go with forms auth. It feels rather clumsy to have a separate app just for the login.
dr_draik
A: 

(More for completeness of information really)

I asked a .Net security guy this question at a conference a while back. His response was that it is technically possible, but he'd never seen it done (and to let him know if I did it and it worked!).

He suggested the way it could be done was by making your own ISAPI filter an installing it into IIS. The ISAPI filter would intercept the requests and basically do the job that IIS does when using integrated authentication, but fall back to using forms if this was not present. This involved some complicated challenge/response logic in the filter. This was for IIS6 though, so it might be different in IIS7.

Whilst this might be technically possible, I wouldn't suggest this route as it feels like a bit of a hack, and rolling your own security is never really a good idea (unless you really know what you are doing).

adrianbanks
Thanks for the input - it's a tad annoying that this is no longer possible (or is practically no longer possible) but I suppose it's the price of progress.
dr_draik
A: 

There are plenty articles on mixing the authenticaton by setting config to use the forms with allowing anonymous access to the app. Secondly, a page for integrated auth should be created with IIS settings set to deny anonymous and use Intgrated Authentication. There you would the magic trick by checking the "Logon_User" variable of the requets's ServerVariables collection. And finally for integrated authentication to silently sign in the user it has to have short hosted name. So if your forms authentication piece is exposed to internet via FQDN there should be some kind of redirect to the short host page. I think it is possible to achieve with just one application under IIS with 2 virtual directories.

Max Malygin