|
-
May 28th, 2003, 03:51 PM
#1
Thread Starter
PowerPoster
Imports System.Security.Principal
How can I identify the name of the user that is browsing to my page from the network?
-
May 28th, 2003, 04:26 PM
#2
PowerPoster
Try something like
HttpContext.CurrentUser.Identity.Name
That was off the top of my head, but it is pretty close...
-
May 28th, 2003, 04:27 PM
#3
PowerPoster
-
May 29th, 2003, 08:52 AM
#4
Thread Starter
PowerPoster
Originally posted by hellswraith
Try something like
HttpContext.CurrentUser.Identity.Name
That was off the top of my head, but it is pretty close...
Well when I do it in debug the string comes up empty.
Code:
Dim str As String = HttpContext.Current.User.Identity.Name
-
May 29th, 2003, 09:06 AM
#5
I believe you have to Autheticate the person first which is what the link hw posted seems to point to.
-
May 29th, 2003, 09:22 AM
#6
in my web.config, I did this
Code:
<authorization>
<allow users="wrbafres/candersen" /> <!-- Allow all users -->
<deny users="?"/>
<!-- <allow users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
<deny users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
-->
</authorization>
and httpcontext.current.user.etc.etc worked. Problem is of corse, now you would have to do it for all users. Im not surehow to do it otherwise. There might be some way.
-
May 29th, 2003, 09:31 AM
#7
D'oh..silly me. I got it
Code:
<authentication mode="Windows" />
<authorization>
<deny users="?" /> <!-- Deny Anonymous
</authorization>
And this worked
Code:
Dim acc As New System.Security.Principal.WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent())
Dim username As String = wp.Identity.Name
Response.Write(HttpContext.Current.User.Identity.Name.ToString())
Response.Write(wp.Identity.Name)
The top REsponse.write, returned my network login
the 2nd returned the account asp.net is running under (ie mycomputer\ASPNET)
-
May 29th, 2003, 09:41 AM
#8
Thread Starter
PowerPoster
Originally posted by Cander
D'oh..silly me. I got it
Code:
<authentication mode="Windows" />
<authorization>
<deny users="?" /> <!-- Deny Anonymous
</authorization>
And this worked
Code:
Dim acc As New System.Security.Principal.WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent())
Dim username As String = wp.Identity.Name
Response.Write(HttpContext.Current.User.Identity.Name.ToString())
Response.Write(wp.Identity.Name)
The top REsponse.write, returned my network login
the 2nd returned the account asp.net is running under (ie mycomputer\ASPNET)
Change acc to wp
-
May 29th, 2003, 09:42 AM
#9
oops. yeah I know. I was in the process of making the variable name more descriptive before I posted it to you. I just didnt finish.
-
May 29th, 2003, 09:45 AM
#10
Thread Starter
PowerPoster
How do I do this authentication on specific pages and not on the whole project?
-
May 29th, 2003, 09:52 AM
#11
hmm. I think you will have to something like store what users/roles can access specific pages in a database or something then just do quick simple If statements and deny access to a page
So in other words
Code:
If HttpContext.Current.User.Name = "Domain\Candersen" Then
' Do something
End If
it might be easier to map sepcific user to roles on the asp.net server, then you can check if a user is in a specific role and deny them access if not, or redirect them.
If using the Role checking, you can do
Code:
If HttpContext.Current.User.IsInRole("Thiscomputer\Managers") Then
' balh
End If
-
May 29th, 2003, 09:53 AM
#12
Thread Starter
PowerPoster
Do I place that logic on the specific pages?
-
May 29th, 2003, 09:56 AM
#13
Thread Starter
PowerPoster
Testing locally on the network, I can't seem to login!
-
May 29th, 2003, 09:58 AM
#14
PowerPoster
Originally posted by jesus4u
How do I do this authentication on specific pages and not on the whole project?
Create a seperate directory for the pages that require authentication. For the directory that contains pages that require authentication, add a web.config file to the directory, and specify the type of authentication.
-
May 29th, 2003, 09:58 AM
#15
Originally posted by jesus4u
Do I place that logic on the specific pages?
yes
-
May 29th, 2003, 09:59 AM
#16
Originally posted by jesus4u
Testing locally on the network, I can't seem to login!
-
May 29th, 2003, 09:59 AM
#17
Thread Starter
PowerPoster
thanks for all the help but I just can't seem to login
-
May 29th, 2003, 10:01 AM
#18
can you post your web.config? Maybe you got something funky in there?!?!?!
-
May 29th, 2003, 10:01 AM
#19
Thread Starter
PowerPoster
Originally posted by Cander
When I get the Win Box and enter my un and pw and domain, I get denied.
-
May 29th, 2003, 10:02 AM
#20
Thread Starter
PowerPoster
Originally posted by Cander
can you post your web.config? Maybe you got something funky in there?!?!?!
Code:
<authorization>
<deny users="*"/> <!-- Allow all users -->
<allow users="apolajenko"
roles="[comma separated list of roles]"/>
<!-- <deny users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
-->
</authorization
-
May 29th, 2003, 10:05 AM
#21
yep..soemthing funky
deny users="*"/>
asterix needs to be ?
-
May 29th, 2003, 10:06 AM
#22
Thread Starter
PowerPoster
-
May 29th, 2003, 10:07 AM
#23
your welcome
-
May 29th, 2003, 10:38 AM
#24
Thread Starter
PowerPoster
What I noticed is that with this setting it allows anyone in and your other code then can read who they are on the network. But if I change the code to any other setting like <allow users="myname" then it does not authenticate like you would expect.
Code:
<authorization>
<deny users="?"/> <!-- Allow all users -->
<allow users=""
roles="[comma separated list of roles]"/>
<!-- <deny users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
-->
</authorization>
-
May 29th, 2003, 10:45 AM
#25
can you show me an example of the config you say doesnt authenticate?
-
May 29th, 2003, 10:47 AM
#26
Thread Starter
PowerPoster
it is above your last post
-
May 29th, 2003, 10:49 AM
#27
well if that is how you allow users looks, then of course it isnt going to wor k
<allow users=""
roles="[comma separated list of roles]"/>
???
-
May 29th, 2003, 10:51 AM
#28
Thread Starter
PowerPoster
Originally posted by Cander
well if that is how you allow users looks, then of course it isnt going to wor k
<allow users=""
roles="[comma separated list of roles]"/>
???
I know but even if I put my name in there it apparently lets me in but then when my buddy next to me visits the same page and he is not in the list he can still see the page when he is not supposed to.
-
May 29th, 2003, 10:53 AM
#29
ok..try this, change the deny user to an *, but make sure it is on the line AFTER the allow users element.
-
May 29th, 2003, 10:57 AM
#30
Thread Starter
PowerPoster
Like this?
Code:
<authorization>
<allow users="apolajenko"
roles="[comma separated list of roles]"/>
<!-- <deny users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
-->
<deny users="*"/> <!-- Allow all users -->
</authorization>
Nope! I don't get authenticated
-
May 29th, 2003, 10:57 AM
#31
take this out
roles="[comma separated list of roles]"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|