2

Possible Duplicate:
What is a NullReferenceException in .NET?

I'm having trouble deploying an asp.net .NET 4.5 website to a IIS 7 server running on Windows 2008 R2, which is running in a remote virtual machine. When I try to access a restricted member page in the virtual server in my machine(aka debuging in VS2012) it works perfectly, redirecting my to the login page in order for the user to log in and access the member page.

However, when I do the exact same thing in the website hosted in IIS7 I get the following error:

Server Error in '/WebApp' Application.

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: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[NullReferenceException: Object reference not set to an instance of an object.]
   WebApp.Members.RedeSocial.Page_Load(Object sender, EventArgs e) +88
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
   System.Web.UI.Control.OnLoad(EventArgs e) +92
   System.Web.UI.Control.LoadRecursive() +54
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

I've researched the hell out of this and cannot find a solution to this. Any ideas? Thanks

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace WebApp.Members
{
    public partial class RedeSocial : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
                Service.Service1Client serv = new Service.Service1Client();
                Library.Utilizador u = Library.Utilizador.loadByUsername(HttpContext.Current.User.Identity.Name);
                dimRede.Text = serv.GetTamanhoRede(u.CODUTILIZADOR);
        }
    }
}
Community
  • 1
  • 1
Nuno Neto
  • 303
  • 2
  • 4
  • 15
  • 2
    Any chance you could show what's on line 88 of your `Page_Load` method of the `RedeSocial.aspx` WebForm? It looks like where the exception originates. – Darin Dimitrov Jan 12 '13 at 23:04
  • 1
    It doesn't have a line 88, it only as 20 lines. This error occurs in all member pages that the users tries to access when not logged in. The stack above is only one of the examples. Despite the fact that someone has mark my question down for lack of research effort, I've had this problem for several days and researched as much as I can... – Nuno Neto Jan 12 '13 at 23:08
  • 1
    Alright, then show your Page_Load method. It doesn't really matter that there's no line 88. Just show some code if you expect any help. – Darin Dimitrov Jan 12 '13 at 23:11
  • 1
    Almost all cases of NullReferenceException are the same. Please see "[What is a NullReferenceException in .NET?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net)" for some hints. – John Saunders Jan 12 '13 at 23:14
  • 1
    Sorry, i forgot it. Added it to the original post – Nuno Neto Jan 12 '13 at 23:14
  • 2
    @NunoNeto did you find the solution causing this error? – jkyadav Jul 31 '15 at 05:56

1 Answers1

1

There are several things that could be going on here, but I'm going to hazard a guess that your problem is with this expression:

HttpContext.Current.User.Identity.Name

Have you configured IIS 7 to use Windows Authentication?

enter image description here

Adam Maras
  • 26,269
  • 6
  • 65
  • 91
  • 1
    I've tried the exact same settings as you have there before and when I try to access the website I get a 500 Error. Is there anything I need to add to the web.config in order to match that in IIS7? – Nuno Neto Jan 12 '13 at 23:33
  • 1
    I don't dont know if it has something to do with the problem, but the website, wich is in .NET 4.5 is running on an App Pool in .Net 4.0. I've installed all the role services and features that have to do with .Net and asp and still I don't have the option, on the basic settings of the app pol to switch to .net 4.5(only 2.0 and 4.0) – Nuno Neto Jan 13 '13 at 10:25
  • 1
    It turned out to be the web.config of the folder containing the webpages producing the error not being deployed to iis7 bescause of being hidden. – Nuno Neto Jan 15 '13 at 15:17