i have live web site. At login to Admin module i'm getting this error.how ever my site works fine at past few days. without any new upload copy i'm getting this error. Server Error in '/' 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:
Line 73: <div id="ctl00_pnlloginname" style=" float:right; width:auto; padding-left:2px; padding-top:3px; padding-right:5px; height:20px;">
Line 74:
Line 75: Welcome <span class="subtitle"><span id="ctl00_lblloginname12"><asp:Label ID="lbldisplayname" runat="server"></asp:Label></span></span> | Online Users Found : <span class="subtitle"><asp:Label ID="lblonlineusers" runat="server"><%= Application["OnlineUsers"].ToString()%></asp:Label></span> | You Have <asp:Label ID="lblnewunreadmail" runat="server" CssClass="subtitle"></asp:Label> unread email in <a href="Pop3Client.aspx" class="subtitle">Gmail Inbox</a> | <a href="Report.aspx" class="subtitle">Track Report</a></div></td>
Line 76: <tr>
Line 77: <td height="34" align="center" valign="top" class="menu_bg">
Source File: c:\hostingspaces\ominvest\ominvestment.co.in\wwwroot\Admin\MasterPage.master Line: 75
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
ASP.admin_masterpage_master.__Renderlblonlineusers(HtmlTextWriter __w, Control parameterContainer) in c:\hostingspaces\ominvest\ominvestment.co.in\wwwroot\Admin\MasterPage.master:75
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.WebControls.Label.RenderContents(HtmlTextWriter writer) +8697071
System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +32
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +163
System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +32
System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +51
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +40
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Control.Render(HtmlTextWriter writer) +10
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Page.Render(HtmlTextWriter writer) +29
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266
Version Information: Microsoft .NET Framework Version:2.0.50727.5466; ASP.NET Version:2.0.50727.5456
i don't have idea what problem is that.
我不知道那是什么问题。
Global.asax
Global.asax中
string _pagePath;
void Application_Start(object sender, EventArgs e)
{
Server.ClearError();
Application["OnlineUsers"] = 0;
// Caching the tracker image in memory
byte[] trackerImg = File.ReadAllBytes(Context.Request.MapPath(ConfigurationManager.AppSettings["SD_Tut_ImageFileLocation"]));
Application[ConfigurationManager.AppSettings["SD_Tut_ImageFileKeyName"]] = trackerImg;
// Creating a new request queue collection
int queueCapacity = Convert.ToInt32(ConfigurationManager.AppSettings["SD_Tut_TrackerRequestsToCache"]);
Queue<TrackerRequest> trackerReqQueue = new Queue<TrackerRequest>(queueCapacity);
Application[ConfigurationManager.AppSettings["SD_Tut_TrackerCachedRequestsKeyName"]] = trackerReqQueue;
}
void Session_Start(object sender, EventArgs e)
{
Session["username"] = Server.HtmlEncode(User.Identity.Name);
if (Session.IsNewSession && Session["username"] == null)
{
_pagePath = Server.MapPath("Default.aspx");
Response.Redirect(_pagePath);
}
Application.Lock();
Application["OnlineUsers"] = (int)Application["OnlineUsers"] + 1;
Application.UnLock();
}
void Session_End(object sender, EventArgs e)
{
Application.Lock();
Application["OnlineUsers"] = (int)Application["OnlineUsers"] - 1;
Session.Remove("username");
Session.Clear();
Application.UnLock();
}
2 个解决方案
#1
1
Try changing this:
尝试改变这个:
Application["OnlineUsers"].ToString()
to this:
对此:
(Application["OnlineUsers"] ?? 0).ToString()
#2
1
You are trying to convert a null value in string, this is not possible and will eventually lead to this exception.
您正在尝试在字符串中转换空值,这是不可能的,并最终将导致此异常。
Application["OnlineUsers"]
might be null, and when you call .ToString()
from that expression on line 75 the exception is thrown. Better to check for null in advance.
可能为null,当您从第75行的表达式调用.ToString()时,将抛出异常。最好提前检查null。
#1
1
Try changing this:
尝试改变这个:
Application["OnlineUsers"].ToString()
to this:
对此:
(Application["OnlineUsers"] ?? 0).ToString()
#2
1
You are trying to convert a null value in string, this is not possible and will eventually lead to this exception.
您正在尝试在字符串中转换空值,这是不可能的,并最终将导致此异常。
Application["OnlineUsers"]
might be null, and when you call .ToString()
from that expression on line 75 the exception is thrown. Better to check for null in advance.
可能为null,当您从第75行的表达式调用.ToString()时,将抛出异常。最好提前检查null。