我在本地沒有問題從.net MVC應用程序獲取請求的數據,但在服務器上,ajax jquery調用報告500錯誤。通常,我可以在本地單步執行代碼,找出可能導致服務器上出現500錯誤的「可能」。500錯誤之謎只發生在服務器上
這一次,我意識到,我真的需要一個更好的編碼策略,以捕獲錯誤,要麼登錄或將它們向我彙報
public ActionResult PhotoList(int tblGateCode_ID)
{
try
{
context = new DBGate();
var images = context.tblGateCodeImages.Where(x => x.tblGateCode_ID == tblGateCode_ID);
foreach (var img in images)
{
img.GatePhoto = null;
}
ViewModel viewModel = new ViewModel
{
GateCodeImageList = images.ToList()
};
return Json(viewModel, "application/json", JsonRequestBehavior.AllowGet);
}
catch (Exception e)
{
//??
}
}
}
更新:
我也嘗試添加在代碼到我的捕獲
catch (Exception e)
{
return Json(e.Message, "application/json", JsonRequestBehavior.AllowGet);
}
要麼我不被允許這樣做...或者其他一些原因我仍然得到500?
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
你可以使用你的瀏覽器工具(網絡選項卡),以檢查響應,並看到錯誤 –
響應的更多細節只是不夠好,我想要做的只是傳回例外。所以我想e.Message –
你有多少訪問服務器?如果您可以查看事件日誌,則可以將exception.message寫入事件日誌以幫助調試。 https://support.microsoft.com/en-us/kb/307024 –