【问题标题】:Is there an enum or class in .NET containing the WebDAV http status codes.NET 中是否有包含 WebDAV http 状态代码的枚举或类
【发布时间】:2011-07-01 10:46:41
【问题描述】:

我一直使用HttpStatusCode enumeration (msdn) 来返回网络请求中的错误,但现在我想返回422, "Unprocessable Entity" (webdav.org),我发现它不在枚举成员中。

我在 .NET 框架中找不到任何东西,如果我能提供帮助(即如果确实存在某些东西),我想avoid custom solutions (devio.wordpress.org)

场景是这样的:客户端发布请求,并且在服务器中进行验证。在对 SO 进行快速搜索后,我决定 422 is perhaps most appropriatemaybe a 400

那么,有谁知道 .NET 4.0 中是否有包含 WebDAV http 状态码的枚举或类?

谢谢!

【问题讨论】:

    标签: .net http-status-codes


    【解决方案1】:

    不,没有定义这样的文件——我对正在构建的 API 有相同的要求,并决定像这样简单地对它进行类型转换(这可以使用 int 枚举):

    try {
        if (!Repository.Cancel(IdHelper.Decrypt(id))) {
            return Request.CreateResponse(HttpStatusCode.NotFound, "Booking not found");
        }
    }
    catch (Exception x) {
        // typecast 422 to enum because it's not defined in HttpStatusCode
        return Request.CreateResponse((HttpStatusCode)422, x.Message);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-13
      • 1970-01-01
      • 2013-11-05
      • 2022-11-02
      • 2022-01-22
      • 1970-01-01
      相关资源
      最近更新 更多