We have an ASP.NET MVC 4 intranet application. We’re using Windows Authentication and that aspect works fine. The user’s credentials are used and we can access those credentials from the web app.
What we really want is some sort of hybrid mode, however. We want to get the user’s credentials from the browser, but we also want to verify that the user is in our application’s database. If the user’s in the database, then they can just continue on. If they’re not, we want to redirect them to a page asking for alternate credentials. What I’m doing now is, in Global.asax.cs
, I’ve got an Application_AuthenticateRequest
method and I’m checking to see if the user is authenticated. If they are and their cookie information doesn’t reflect the fact that they’re logged into the system, then I log them in and set up some cookies with info about the user. If they’re not authenticated, I redirect them to a login page. We can’t use AD roles for reasons involved with company policy, so we need to use the database for additional authentication.
I’m guessing Application_AuthenticateRequest
isn’t the place to do this, but maybe it is. But we basically need a place to filter the requests for authentication. But additionally this implementation leads me to another issue:
We have certain URLs in our app that allow anonymous access. I’ve added <location>
tags to the web.config for these. The problem is, when anonymous calls are made into these, it gets to Application_AuthenticateRequest
and tries to log the user into the DB. Now, I can add code into Application_AuthenticateRequest
to handle these URLs and that’s currently my plan, but if I’m write and Application_AuthenticateRequest
isn’t the place to be doing this, then I’d rather figure it out now than later.
HttpWebRequest.GetResponse()
call.DebugController.FlushCaches()
has [AllowAnonymous] and in theweb.config
I have a<location>
tag forDebug/FlushCaches
that has<allow users="*"/>
. But when myHttpWebRequest
calls it, I get a 401. – Isis