开发者

ASP.NET Request.LogonUserIdentity.Name is null

I have an ASP.NET web form application that on the server side I need to know the user's identity. I do not need to impersonate the user. I just need their username so I can update some records in a database correctly.

When the request is processed I have the following line of code:

string userName = Request.LogonUserIdentity.Name;
if(true == string.IsNullOrEmpty(userName))
{
  logger.logwarning("missing username");
}
else
{
  logger.loginfo("update by {0}", userNam开发者_开发技巧e);
}

In my development & QA environment this works perfectly - I see the userName in the log file and all of the database records have the lastModifiedBy field filled in correctly. However, when we go to production - userName is an empty string!

UPDATE & CLARIFICATION

I should have included this yesterday -

in web.config we have we do not want to impersonate the user b/c they will not have access to the backend system (Microsoft CRM) but the service account does.

Inside IIS we have anonymous access turned off and Windows Integrated Security turned on. The application is running in its own Virtual Directory and has an application and app pool assigned to it.

Overall the stuff appears the same as our staging server. I know diagnosing this via a short post on stack overflow is a PITA, but I'm grasping for staws at this point. I know this is something really lame like a checkbox I forgot to click or a minor little setting that usually doesnt matter.

Anyway, I apperciate any suggestions that come my way.


Have you switched off Anonymous Access to the web app?


Ensure that you have your web application/virtual directory in IIS setup correctly.

To configure Windows authentication

Start Internet Information Services (IIS). Right-click your application's virtual directory, and then click Properties. Click the Directory Security tab. Under Anonymous access and authentication control, click Edit. Make sure the Anonymous access check box is not selected and that Integrated Windows authentication is the only selected check box.

In your application's Web.config file or in the machine-level Web.config file, ensure that the authentication mode is set to Windows as shown here.

<system.web><authentication mode="windows" /><system.web>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜