How can I identify the name of the user that is browsing to my page from the network?
Printable View
How can I identify the name of the user that is browsing to my page from the network?
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.Quote:
Originally posted by hellswraith
Try something like
HttpContext.CurrentUser.Identity.Name
That was off the top of my head, but it is pretty close...
Code:Dim str As String = HttpContext.Current.User.Identity.Name
I believe you have to Autheticate the person first which is what the link hw posted seems to point to.
in my web.config, I did this
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. :confused: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>
D'oh..silly me. I got it
And this workedCode:<authentication mode="Windows" />
<authorization>
<deny users="?" /> <!-- Deny Anonymous
</authorization>
The top REsponse.write, returned my network loginCode: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 2nd returned the account asp.net is running under (ie mycomputer\ASPNET)
Change acc to wpQuote:
Originally posted by Cander
D'oh..silly me. I got it
And this workedCode:<authentication mode="Windows" />
<authorization>
<deny users="?" /> <!-- Deny Anonymous
</authorization>
The top REsponse.write, returned my network loginCode: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 2nd returned the account asp.net is running under (ie mycomputer\ASPNET)
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. :p
How do I do this authentication on specific pages and not on the whole project?
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
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.Code:If HttpContext.Current.User.Name = "Domain\Candersen" Then
' Do something
End If
If using the Role checking, you can do
Code:If HttpContext.Current.User.IsInRole("Thiscomputer\Managers") Then
' balh
End If
Do I place that logic on the specific pages?
Testing locally on the network, I can't seem to login!
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.Quote:
Originally posted by jesus4u
How do I do this authentication on specific pages and not on the whole project?
yesQuote:
Originally posted by jesus4u
Do I place that logic on the specific pages?
:confused:Quote:
Originally posted by jesus4u
Testing locally on the network, I can't seem to login!
thanks for all the help but I just can't seem to login
can you post your web.config? Maybe you got something funky in there?!?!?!
When I get the Win Box and enter my un and pw and domain, I get denied.Quote:
Originally posted by Cander
:confused:
Quote:
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
yep..soemthing funky
deny users="*"/>
asterix needs to be ?
Quote:
Originally posted by Cander
yep..soemthing funky
deny users="*"/>
asterix needs to be ?
:p :p :p YEP! Got it to work! Thanks
your welcome ;)
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>
can you show me an example of the config you say doesnt authenticate?
it is above your last post
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.Quote:
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]"/>
???
ok..try this, change the deny user to an *, but make sure it is on the line AFTER the allow users element.
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
take this out
roles="[comma separated list of roles]"