Windows Server - Problem acessing TS - Asked By Dom Afonso on 25-Jun-12 02:25 PM

Earn up to 30 extra points for answering this tough question.
I installed Terminal Server on Windows Server 2008 Standard and when I run it in the browser, I get the following error:

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 18: 
Line 19:         System.Security.Principal.WindowsPrincipal wUser = User as System.Security.Principal.WindowsPrincipal;
Line 20:         if (wUser.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator) || User.IsInRole("TS Web Access Administrators"))
Line 21:             fUserAdmin = true;
Line 22:         else

Source File: c:\Windows\Web\ts\en-US\Default.aspx Line: 20

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   ASP.en_us_default_aspx.Page_Init(Object sender, EventArgs e) in c:\Windows\Web\ts\en-US\Default.aspx:20
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +24
   System.Web.UI.Page.OnInit(EventArgs e) +104
   System.Web.UI.Control.InitRecursive(Control namingContainer) +132
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1969

Do anyone know how to solve this?
Robbe Morris replied to Dom Afonso on 25-Jun-12 02:29 PM
I see an IF statement comparing wUser and User.  Are these the same object?
Peter Bromberg replied to Dom Afonso on 25-Jun-12 09:42 PM
You need to put a breakpoint on line 20 and mouse over your wUser etc. variables to see which one is null. What kind of IIS authentication do you have set for this web application? You need to uncheck anonymous and choose Windows if you expect to get any Windows users.
Jitendra Faye replied to Dom Afonso on 26-Jun-12 12:29 AM
This problem comes when you try to get or set values from any  null object.

so before fetching or setting value first check that is it null or what.

check for object where you are getting error.



In your code check for this line-

System.Security.Principal.WindowsPrincipal wUser = User as System.Security.Principal.WindowsPrincipal;

First check -
wUser  is null or what , if it is null then you will get this error.