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

Calculate a simple angle
c# get data from application (Hearthstone)
Removing extra letter sets in an inconsistent text file using Regex
passing multiple objects as parameters to mvc 6 action
Weird behaviour of c# compiler due caching delegate
C# file upload via multipartform extremely slow on large files
How do I convert a method in an Entity Framework model into an Expression?
Check if string contains at least one part of an enum
Get and uncompress the p7z contents by MimeKit
Upload multiple File Using angularjs with custom data for each one?
Trying to check an image whether it is tapped in if condition in uwp
Defining multiple Id columns using Marten?
Outlook Addin 2010 event for ribbon tab load
Sending emails locally from my Domain to email outside the domain
How can I use petapoco with sync and async Repository pattern + Unit of Work?
SmartFoxServer with Unity Logging issue

Categories

HOME
oracle-sqldeveloper
opc-ua
sdk
atlassian-fisheye
gnuradio
revit-api
pyodbc
minimax
kairosdb
versioning
airbnb
hololens
gsuite
traveling-salesman
tftp
mex
multiple-inheritance
andengine
slim-lang
log4net-configuration
visual-prolog
luhn
webspeech-api
traitsui
minitest
sampling
ansible-inventory
azure-vm-scale-set
mkdir
dotnetnuke-module
taiga
f#-fake
risc
html-entities
weld
qtwebkit
hdpi
noise
multivalue
jcs
openidm
sp
android-vectordrawable
grib
business-catalyst
sharing
portaudio
require-handlebars
system-integration
aws-kms
user-profile
sqlxml
bbedit
periodic-processing
ideavim
trendline
markerspiderfier
gulp-cdnizer
libgcrypt
php-gd
edgar
windows-phone-8-emulator
genome
mergecursor
parseexception
nfa
bungeecord
applinks
optimistic-locking
cordova-3
drools-guvnor
indic
enquire.js
pidgin
pthreads-win32
misfire-instruction
zend-db-table
oc4j
listpicker
wpd
stringstream
generator-expression
blotter
boost.build
moonscript
rfc822
webpage-screenshot
visual-leak-detector
cherokee
parallel-python
hwnd
xhtmlrenderer
html5-animation
nyromodal
dongle
user-preferences
expander

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