【问题标题】:Object reference not set to an instance of an object in IIS 7 [duplicate]对象引用未设置为 IIS 7 中的对象实例 [重复]
【发布时间】:2013-01-12 23:01:47
【问题描述】:

可能重复:
What is a NullReferenceException in .NET?

我在将 asp.net .NET 4.5 网站部署到在远程虚拟机中运行的 Windows 2008 R2 上运行的 IIS 7 服务器时遇到问题。 当我尝试访问我机器中虚拟服务器中的受限成员页面时(也就是在 VS2012 中调试),它运行良好,将我重定向到登录页面,以便用户登录并访问成员页面。

但是,当我在 IIS7 中托管的网站中执行完全相同的操作时,我收到以下错误:

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

我已经对此进行了彻底的研究,但找不到解决方案。 有任何想法吗? 谢谢

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);
        }
    }
}

【问题讨论】:

  • 您是否有机会展示RedeSocial.aspx WebForm 的Page_Load 方法的第88 行的内容?看起来异常的来源。
  • 没有88行,只有20行。此错误发生在用户在未登录时尝试访问的所有成员页面中。上面的堆栈只是示例之一。尽管有人因为缺乏研究努力而将我的问题记下来,但我已经遇到这个问题好几天了,并且尽可能多地研究......
  • 好的,然后显示您的 Page_Load 方法。没有第 88 行并不重要。如果您需要任何帮助,只需显示一些代码即可。
  • 几乎所有的 NullReferenceException 情况都是一样的。请参阅“What is a NullReferenceException in .NET?”获取一些提示。
  • @NunoNeto 您找到导致此错误的解决方案了吗?

标签: asp.net iis windows-server-2008-r2


【解决方案1】:

这里可能会发生几件事,但我会冒险猜测您的问题出在这个表达式上:

HttpContext.Current.User.Identity.Name

您是否已将 IIS 7 配置为使用 Windows 身份验证?

【讨论】:

  • 我已经尝试了与您之前完全相同的设置,当我尝试访问该网站时,我收到 500 错误。有什么我需要添加到 web.config 以匹配 IIS7 中的内容吗?
  • 我不知道它是否与问题有关,但 .NET 4.5 中的网站正在 .Net 4.0 中的应用程序池上运行。我已经安装了与 .Net 和 asp 相关的所有角色服务和功能,但我仍然没有选项,在应用程序 pol 的基本设置上切换到 .net 4.5(仅 2.0 和 4.0)
  • 原来是包含网页的文件夹的 web.config 由于被隐藏而导致错误未部署到 iis7。
猜你喜欢
  • 2010-09-12
  • 1970-01-01
  • 2021-04-19
  • 1970-01-01
  • 2020-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-03
相关资源
最近更新 更多