web app on IIS 7 login error

wiggy353
wiggy353 used Ask the Experts™
on
I have a web app that I made in Visual Studio 2010. It works fine when testing in visual studio. I have put it on an IIS 7 web server and am having problems. The error I am getting is:

Login failed for user 'MASTER\PIGSTEST$'.

The code that I have in the app to get the user is:

        protected void Page_Load(object sender, EventArgs e)
        {
            string userName;
            string userDomain;
            string user = HttpContext.Current.User.Identity.Name.ToString();
            string[] usernameArray = user.Split('\\');
            userDomain = usernameArray[0];
            userName = usernameArray[1];

            lblPbmSiteMasterUserName.Text = userName.ToString();
            string versionInfo = Assembly.GetExecutingAssembly().GetName().Version.ToString();
            lblBuildVersionPbmSite.Text = versionInfo;
             
        }

Open in new window


The username that it is showing in the error isn't my user name when going to the page. The domain is correct, but the username is the name of the computer that is the webserver with a $ on the end. I'm not sure what's happening here...

Thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Open up the computer manager and see what account is setup to run the Application Pool of the IIS website instance. Additionally, check to see what Authentication is specified on the site. The default is "Anonymous", where you probably want "Windows authentication".
It really just sounds like you have Anonymous authentication enabled, so if you disable that and enable Windows, that should work.

http://technet.microsoft.com/en-us/library/cc754628(WS.10).aspx

User Interface
1. Open IIS Manager and navigate to the level you want to manage. For information about opening IIS Manager, see Open IIS Manager (IIS 7). For information about navigating to locations in the UI, see Navigation in IIS Manager (IIS 7).
2. In Features View, double-click Authentication.
3. On the Authentication page, select Windows Authentication.
4. In the Actions pane, click Enable to use Windows authentication.


As long as you are running on a server product you are fine. As noted "Windows Authentication is not supported Home or Starter editions of Windows Vista® and Windows® 7"

Author

Commented:
I was thinking that might be it, but I have it set to Windows authentication.
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Author

Commented:
I created a test site that uses the same code to get username information. It works fine using the default application pool, but if I change it to the .NET 4.0 application pool it does not work any more. The only difference that I can see is the version of the .NET framework. Is there something in the 4.0 framework that conflicts with the code?

Author

Commented:
Something this simple:

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("Current User: <strong>" + System.Environment.UserName + "</strong><br><br>");
        Response.Write("Current User: <strong>" + HttpContext.Current.User.Identity.Name.ToString() + "</strong>");
    }

Open in new window


Is braking when I set the .Net Framework to 4.0. It works fine in 2.0...???
What is the identity of the .NET 4.0 app pool? If you go to the Application Pools and click Advanced Settings, there is a field called "Identity". Try setting that to "AppPoolIdentity", as that user has the default permissions required.

Author

Commented:
It was set to Network. I changed it to ApplicationPoolIdentity but it didn't make a difference. The error I get when going to the page is:

Server Error
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.
Commented:
Just so everyone knows, this turned out to be a known issue with ASP.NET 4. For information on it look here:

http://www.asp.net/learn/whitepapers/aspnet4/breaking-changes#0.1__Toc256770149

Author

Commented:
I found this answer somewhere else.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial