Link to home
Create AccountLog in
Avatar of paradigm_IS

asked on

http context question

I am using the following line of code to determine who is using my web application:

Dim user As String = HttpContext.Current.User.Identity.Name.Split("\").ElementAt(1)

This works fine when running through Visual Studio 2010, but after I deploy it to the web server, it cannot find the user.

Anyone have any ideas why?
Avatar of Kumaraswamy R
Kumaraswamy R
Flag of India image

Avatar of paradigm_IS


I beg your pardon?  The link sends me to a subject called "How to replace the html tag from the ajax html edior - text", which does not have anything to do with my question?
Does "cannot find the user" mean that you are getting an error parsing the username, or that your "user" variable is empty? Is your site configured to allow anonymous access?
carl tawn, the user variable is empty.  can you explain what you mean by site configured to allow anonymous access?

Basically, there is a sharepoint site set up, and it includes a link which takes them to the web site.  The default page of the web site loads fine, but it does not see the user (i..e the value in the user variable....)
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
carl tawn, that seems to have worked, in that it now seess the windows domain user name.  Thanks very much for that.

Perhaps you could explain to me what anonymous access entails, like when it might be used?  I'm a bit new to the subject of website security and directory security?

More importantly, by unchecking anonymous security, is the web site still safe?  As I mentioned before, the website is navigated to by the user clicking on a link provided in the sharepoint page.  This sharepoint site is only accessible by the employees of the organization, who are the only people who we want to have access to the web site i'm speaking of.....
Basically if Anonymous access is switched off then a user has to be logged into your domain in order to be able to access the site, which is great for intranet apps. If it is switched off then it allows you to run a website that can be accessed by people who may or may not be logged into your domain. For example, if you are running a public facing website where users who are not part of your domain are allowed access then you would leave Anonymous access switched on.
ah, ok.  One thing about your answer though.  In your second sentence you say, "If it is switched off then it allows you to run a website that can be accessed by people who may or may not be logged into your domain"....did you actually mean to say "switched ON"?  Then your answer makes more sense.
Well spotted :) Yes, the second one should have said ON.
Excellent job.  Thanks carl tawn!
carl tawn, one more thing.  After I unselected anonymous access and clicked OK, a window appeared called Inheritance Overrides, listing what it calls Child Nodes.  The message says

"The following child nodes also define the value of the "UNC Password" property, which overrides the value you have just set.  Please select from the list below those nodes which should use the new value".

And it lists a series of child nodes which are defined under the Default Web Site (where i set anoymous to off), and included in the child nodes is my web site that I have alluded to in this discussion.  (or perhaps I should be calling them virtual directories...?)

So, is this asking me to select which sites should have anonymous checked to "off"?  I hit cancel in response to this window, and even though my site was included in this child node list, it would appear it is not using anonymous access (which is good of course) because the web page now sees who is logged into the domain.  So that struck me as strange that the anonymous access if actually off for my site, even though I hit cancel in response to this window.

So just a little confused as to what this window was asking and what action was performed when I hit cancel.  :-)
If your site is in a VDir rather than being at the root of the website itself then you just want to switch off anonymous access on the VDir, otherwise you risk upsetting other apps running under the same site.

All that dialog is telling you is that some of the applications under the website have a setting that is different to the one you just set for the site, and bascially gives allows you to change them all to the same thing. Clicking cancel will do the same as clicking OK without selecting anything.
as an additional note, my web site (called timesheet) actually a virtual directory under Default Web Site and Default Web Site is where I checked anonymous access to off...
You can set the two independently of each other. Ordinarily you will want to set it at the most restrictive level, in your case on the Virtual Directory.
Great, thanks again carl tawn.