c#


ASP.NET Authentication Troubleshooting


I have a fairly complex web app that was built (by a contractor) to use integrated authentication. As part of the authentication process, a GetNetworkID() function is used that looks like this:
private string GetNetworkID()
{
return HttpContext.Current.User.Identity.Name.Split(new char[] { '\\' })[1];
}
When I run this on my development box, the HttpContext.Current.User.Identity.Name value is
myNetwork\\myUserID, so the above funciton returns my User ID, as intended, and the authenticaiton process works just fine.
But when I run this on my web server, I get an Index was outside the bounds of the array error thrown by the return statement in the GetNetworkID() function.
I'm a bit lost on how to troubleshoot this and how to figure out if it's an IIS configuration issue (my web server is a Windows Server 2008 box running IIS 7), or something else.
If I hard-code my User ID as the return value for the GetNetworkID() function, it works on the web server, but I don't have any great ideas about how to debug on the web server to determine what the HttpContext.Current.User.Identity.Name return value is that's causing the array index error.
Any suggestions?
IIS runs as the IIS Service Account, so Current.User.Identity is likely going to be the name of the IIS Account.
For completeness sake, you should check for '\' either with a Find() or by calling split, and checking the length of the resultant array. If the length is 1, that means the id isn't in the form of domain\username.
In general, if you want to debug, you can write any value to the HTTP Response stream like so:
Response.Write(HttpContext.Current.User.Identity.Name)
Another method is to setup an ASP page variable, and set the page variable to the value you'd like to inspect. You can display the variable value either through ASP code, or through Javascript.
You might be missing an IIS setting.
Try in IIS:
Website (right click) | Properties | Directory Security (tab)
Click "Edit..."
Then select "Integrated Windows Authentication"
I think the user that logs into your web applciation on the other server, is not a valid login. And hence a result is not returned on User.Identity.Name.
Like you said, it works when you hardcoded the username.
This means, the user creditials of the PC you are using to login is not permitted on your site. This therefore must be different to the credentials you are hardcoding.
Best bet is to debug on web server (it isn't hard - all you want to return is the User.Identity.Name and you can get the username and deduce logic from there), and verify the contents in your web.config file.
As Alan pointed out (and I upvoted him for it) you probably want to add a check on what form the User.Identity.Name takes. An updated routine could for example look like this:
private string GetNetworkID()
{
var name = HttpContext.Current.User.Identity.Name;
return name.InStr("\\") > -1 ? name.Split("\\")[1] : name;
}
This will return the second part of the login name if a \ is present, and the full string if not.

Related Links

Using C# to duplicated PHP serialized data in MySQL
HyperLink text not rendered after controls are added
blocking timer in windows service
Write to text files
Web Service Client(Console App) not working on Windows Server 2008 R2 Standard Edition
Process Vector is input's neural of Input Layer of Neural network
How to open a folder in C#.net
How to embed lua (or some other scripting language) in a C# 5.0 application
How to create partially client area in UserControl?
Custom validation client side ignores invalid state
DeploymentItemAttribute doesn't work (correct)
Get a cell value in gridview selected row
MobileAppTracking doesn't work
C# Outlook 2007 Addin + Embedded Assemblies
Automapper unflatten with prefix
Error On Setting The Property MaximizedBounds in c# WinForm

Categories

HOME
redux
ssh
packet
file-upload
coordinates
genexus
webpack-dev-server
aws-sdk-cpp
chef-recipe
browsermob
react-select
responsive
openam
airbnb
indri
project-reactor
ampscript
beaker-notebook
waterfall
pixels
marionette
launchd
dynamic-memory-allocation
recreate
xlib
openoffice-impress
edsdk
minitest
mediastream
lfe
azure-web-roles
google-chrome-console
compiled-query
django-cors-headers
ack
jks
runner
serialversionuid
standard-error
dotnet-cli
opticalflow
try-catch-finally
printer-control-language
toggleclass
settext
hdr
boost-range
tinybox2
cosign-api
particle-system
sprockets
vitamio
periodic-processing
firefox-os
nslocalizedstring
magnet-uri
jcomponent
notice
android-togglebutton
avrcp
nfa
pymol
indices
pysvn
fxmlloader
zoneminder
parallel-port
visual-c#-express-2010
starling-framework
nativequery
myrrix
wpa
kademlia
pudb
servicemanager
pymel
linqdatasource
quit
configurationsection
openafs
php-gettext
visual-leak-detector
zend-validate
parallel-python
opendir
jquery-click-event
netduino
response-time
javah
s60
glassfish-embedded
zend-acl
opengl-to-opengles
httpbrowsercapabilities
jettison

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App