2011-09-07 89 views
0

最近,我在服务器中托管的应用程序中遇到了这些异常。当我重新启动IIS的网站时,错误得到纠正。但我不知道导致此异常的序列,因为我无法调试代码(因为它托管在服务器中)。该应用程序在本地工作正常,没有引发异常。我检查了我的后端。它也是完美的。我确实为我的应用程序中发生的所有错误保留了堆栈跟踪。我会把抛出的异常提供给你参考。C#索引超出了数组的范围

消息

Exception of type `'System.Web.HttpUnhandledException'` was thrown. 

的System.Web

堆栈

at System.Web.UI.Page.HandleError(Exception e) at 
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean 
includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean 
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at 
System.Web.UI.Page.ProcessRequest() at 
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) at 
System.Web.UI.Page.ProcessRequest(HttpContext context) at 
ASP.admin_editvideos_aspx.ProcessRequest(HttpContext context) at 
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 

消息

Index was outside the bounds of the array. 

App_Web_kys31898 

堆栈

at EditVideos.SetSpanAndLabelValues(Video aVideo, EduvisionUser auser) at 
    EditVideos.AssignVideoDetailsToControls(Video aVideo, EduvisionUser auser) at 
    EditVideos.SetValue(Int32 videoId, Int32 categoryId) at 
    EditVideos.SetValuesOnPageLoad() at EditVideos.Page_Load(Object sender, EventArgs e) at 
    System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, 
    EventArgs e) at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, 
    EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at 
    System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean 
    includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 

C#代码:

private void SetSpanAndLabelValues(Video aVideo, EduvisionUser auser) 
{ 
    string uploadedDate = aVideo.UploadedDate.ToString(); 
    string[] dateTimeValue = uploadedDate.Trim().Split(' '); 
    string dateFormat = CommonUtilities.GetCultureDateFormat(dateTimeValue[0]); 
    spn_UploadedDate.InnerHtml = dateFormat + ' ' + dateTimeValue[1] + ' ' + dateTimeValue[2]; 
    spnUploader.InnerHtml = aVideo.Title; 
    spnvideotitle.InnerHtml = ReadUserMessage("DisplayVideoTitle", "VideoTitle").Replace("#title#", aVideo.Title); 
    spanVideoTitle.InnerHtml = ReadUserMessage("DisplayVideoTitle", "VideoTitle").Replace("#title#", aVideo.Title); 
    spnviewermail.InnerHtml = ReadUserMessage("EditVideos", "MailOption").Replace("#Mail#", auser.Email); 
    spnmailvalue.InnerHtml = auser.Email; 
    spnUploaderName.InnerHtml = auser.FirstName; 
    SetVideoFileNameSpan(aVideo); 
    SetThumbnailFileNameSpan(aVideo); 
    if (aVideo.LastUpdatedDate.HasValue) 
    { 
     string LastUpdatedDate = aVideo.LastUpdatedDate.ToString(); 
     string[] updatedDateTimeValue = LastUpdatedDate.Trim().Split(' '); 
     string cultureDateFormat = CommonUtilities.GetCultureDateFormat(updatedDateTimeValue[0]); 
     lblUploadedDate.Text = cultureDateFormat + ' ' + updatedDateTimeValue[1] + ' ' + updatedDateTimeValue[2]; 
    } 
    else 
    { 
     lblUploadedDate.Text = "Not yet updated"; 
    } 
} 

如果您觉得这个问题很模糊,我可以提供更多信息。请帮我找出例外的原因。

感谢

+0

欢迎使用Stackoverflow,请使用{}包含任何代码部分或特殊类型的文本。 –

+0

请提供编辑视频的代码。SetSpanAndLabelValues – onof

+0

@ kalyan。谢谢,我从现在开始做。 – AUSTIN

回答

1
string[] dateTimeValue = uploadedDate.Trim().Split(' '); 

string[] updatedDateTimeValue = LastUpdatedDate.Trim().Split(' '); 

两个拆分,然后假定它们分成您在代码中会发生什么,这些线路,您需要验证它们拆分为正确的关于和值。你也不能像这样分割日期时间,因为日期的显示格式根据你的来源而不同。

使用DateTime.Parse()并改为使用datetie对象。

0

首先,您需要检查是uploadeddate包含[”“],如果包含比你必须写如下语句

string[] dateTimeValue = uploadedDate.Trim().Split(' '); 

否则你必须过去一个简单的字符串,也照顾了在未来的代码。

string dateFormat = CommonUtilities.GetCultureDateFormat(dateTimeValue[0]); 
spn_UploadedDate.InnerHtml = dateFormat + ' ' + dateTimeValue[1] + ' ' + dateTimeValue 

这里的问题是,你上传的代码服务器可能有不同的时间格式,还是其他什么东西被创造一些问题。放一些JavaScript来检查这个值。这是检查该事情的唯一方法。