2011-09-07 37 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來檢查這個值。這是檢查該事情的唯一方法。