Link to home
Start Free TrialLog in
Avatar of Camillia
CamilliaFlag for United States of America

asked on

Windows Authentication asks to authenticate!

I've been at this for a month now. ASP.Net 2.0, WAP model. IIS 6.0, Windows Server 2003.

1. My app has only 2 pages so far. Default.aspx calls Login.aspx.
2. I have windows authentication code in global.asax like this:
  Sub WindowsAuthentication_OnAuthenticate(ByVal Source As Object, _
                         ByVal e As WindowsAuthenticationEventArgs)

        'dont authenticate when on AccessDenied page
        Dim fileName As String = LCase(HttpContext.Current.Request.Url.LocalPath)
        If InStr(fileName, "accessdenied") > 0 Then Exit Sub

        Try
            If e.Identity.IsAuthenticated And Not (e.Identity.IsAnonymous) And _
              e.Identity.AuthenticationType.Length <> 0 Then

                userIdentity = e.Identity.Name()
            Else
                HttpContext.Current.Response.Redirect("AccessDenied.aspx?Authenticated=" + e.Identity.IsAuthenticated.ToString + "&Anonymous=" + e.Identity.IsAnonymous.ToString + "&Type=" + e.Identity.AuthenticationType.ToString)

            End If
        Catch ex As Exception
            HttpContext.Current.Response.Redirect("AccessDenied.aspx?Error=" + ex.Message.ToString)
        End Try

    End Sub

3. I moved the app to our main server. Set up a virtual directory but when I login, I get a pop-up to login with useid/pwd. I tried the app both from my laptop and by sitting at the server and logging in with "admin/pwd".

4. We have Active Directory, so I created a new group. I added this group to the security tab of the folder holding the app. Gave it "full control" . BUT still got the userid/pwd pop-up.

5. I added ASPNET user to the folder holding the app with "full control" but stilll got the userid/pwd pop-up

6. I have both .net 1.1 and 2.0. So for this app, i created a new App Pool and made sure it has the 2.0 framework

7. in IIS, I have Anonymous unchecked and Windows Authenicated checked.

8. in web.config , i have:
 <authentication mode="Windows"  />
        <authorization >
         
            <deny users="?" />
        </authorization>

9. in IIS, I right clicked on "default.aspx" , I  got the userid/pwd pop-up.

What am I missing??
ASKER CERTIFIED SOLUTION
Avatar of ethoths
ethoths

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Camillia

ASKER


 I need to use the code in global.asx because for my app, i need to get the username  who's been authenticated. Authenticated username is used thru out the system... anonymous users cant use the system...

 If I check "anonymous"...wouldnt that defeat purpose of windows authentication?? then anyone could use the system..right?

 I have a "default.aspx" and a "login.aspx". The default.aspx has javascript code to open "login.aspx" in a specified size. The "login.aspx" will be displayed AFTER the user is authenticated. I use "login.aspx" to display database options to the user. This is needed for the app. Users have to choose their database up-front before they can access the system...

 
The "login.aspx" pages doesnt actually ask for userlog/pwd...it only presents to the user a dropdown box to choose which database they want to connect to, what language to use. But they have to be authenticated by then before they get this page.
Avatar of ethoths
ethoths

para 1
You can get the user name at any time from the Page.User object.


para2
No the ASP.Net security sits on top of the IIS and overrides it.


para3
The functionallity in the login.aspx file is fine - just dont call it login.aspx - how about options.aspx?

So, you're saying to do this (before I break what i already have :-) )...

1. remove stuff from global.asax
2. have whatever i have in web.config
3. have windows authentican and anonymous both checked in IIS?

All the examples I've seen in Windows Authentication, they've had that code in global.asax.

yes, good idea not to call it "login.aspx".
Yes. That is what I'm suggesting. In case your not sure just comment out yout global.asax code and it will be a doddle to put it all back again.

Didnt work....  

I removed the code from global.asax.
Changed IIS to have BOTH anonymous and windows authentication.
I kept web.config as is :
<authentication mode="Windows"  />
        <authorization >
         
            <deny users="?" />
        </authorization>

BUT still got the pop-up box to login with useid/pwd. When I checked "anonymous access", i got this pop-up: The following child nodes also define the value of the 'UNCPassword' property, which overrides the value you have just set. Please select from the list below those nodes which should use new value"....

It had "default.aspx" listed and I high-lighted it. But keep getting the pop-up box....

???? mind boggling...
Last shot, try adding the allow option...

<authentication mode="Windows"  />
<authorization >
    <deny users="?" />
    <allow users="*" />
</authorization>
If  I have :
<authorization >
    <deny users="?" />
    <allow users="*" />
</authorization>

Still pops the pop-up asking for username/pwd.

If I have :
<authorization >
    <allow users="*" />
    <deny users="?" />
   
</authorization>

That does NOT pop-up the box but then it's authenticating anonymous access because I have "Label1.Text = Page.User.Identity.Name.ToString" in my second page but it comes out as blank...

so search for my answer contiues :(
This should work and if it allows anonymous  when you reverse the allow/deny then you're very close.

Try this again
<authorization >
    <deny users="?" />
    <allow users="*" />
</authorization>

but do an IIS reset, clear your temporary asp.net files and make sure all your aspnet_wp.exe processes are dead. (Probably best to restart your machine). If that doest work I'll give up but I've done this countless times without a problem.
let me try it but i know i cant restart the server, that's our main server...

but i can restart IIS and make sure the wp is dead.

Let me try and post again.
rebooted the server, cleated temp aspnet files, restarted IIS, cleared internet files, made sure web.config and global have the correct code but nope, still got the pop-up box to enter userid/pwd...

do i need to do anything with the machine.config? anything with the App Pool? i have the app on the H drive of the server, does it need to be in c drive (not that this should matter..just running out of ideas)...


 Could it be a firewall issue (but I go to the server itself and open the site)

 **************This worked on a new server we have!!!  same code, same setup... *************

so how can I tell what's causing the other main server pop-ing up username/pwd??
Hey unfortunately that WinDoze. I can never figure out that security stuff. It seems that you get on crack at it then it gets cached or something and it won't work. Then, for no reason at all it'll just start working. The morale here is to tey t get it right first time I suppose. Anyway, thanks for sticking with me - I though I was going mad for a minute.