【发布时间】:2016-07-10 10:55:36
【问题描述】:
在我的项目中,我使用 OData 3.0,我需要处理来自 SQL 存储过程的错误。这是控制器代码:
public class StartProductionBatchListController : ODataController {
private SitContext<StartProductionBatchModel> db = new SitContext<StartProductionBatchModel>();
[EnableQuery]
[SITAuthorize("/production/ordersOverview")]
public DbRawSqlQuery<StartProductionBatchModel> GetStartProductionBatchList([FromODataUri] string entryId)
{
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters.Add("ENTRY_ID", entryId);
return db.ExecuteProcedure("StartProductionBatch", parameters);
}
}
如果存储过程出错,则使用 SQL 命令 RAISERROR 引发异常。
在我的客户端,我收到两个不同的响应 - 如果我从本地主机连接,我会得到:
{
"odata.error":{
"code":"","message":{
"lang":"en-US","value":"An error has occurred."
},"innererror":{
"message":"The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; charset=utf-8'.","type":"System.InvalidOperationException","stacktrace":"","internalexception":{
"message":"The following materials are not available on the line: 562942",
"type":"System.Data.SqlClient.SqlException","stacktrace":"
... there is the entire stack here
}
}
}
}
...哪里可以看到报错信息(以下材料在线不可用:562942)
如果我在远程计算机上做同样的事情,我会得到以下结果:
{
"odata.error":{
"code":"","message":{
"lang":"en-US","value":"An error has occurred."
}
}
}
我尝试设置我的 IIS 以返回详细错误(在 web.config 中设置 <httpErrors errorMode="Detailed" />),即使它可能是一个安全风险(在这种情况下不是真的,它是一个未发布到 Internet 的 Intranet 应用程序) ,但没有任何帮助。
感谢您的帮助。
【问题讨论】:
标签: .net asp.net-web-api odata