zoukankan      html  css  js  c++  java
  • WebAPI 问题集锦

    一、OWIN 禁用设置

    在项目中添加了 OWIN 的引用,打算后面用到,但是在启动项目的时候报错:

    “No assembly found containing a Startup or [AssemblyName].Startup class.”

    “To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of "false" in your web.config.”

    根据这里的提示,在配置文件(Web.config)中添加配置信息进行禁用 OWIN 的启动:

    <!--禁用OWIN启动-->
    <add key="owin:AutomaticAppStartup" value="false"/>

    二、获取 HttpResponseMessage 中的异常信息

    要在项目中对异常信息做统一的处理,在 Filter 里面做的。

    拦截 StatusCode 在400 以上的异常信息。调试的时候找到了异常信息在 “Response.Content.Value”中,但是在实际的编码中获取不到。

    最后查找到了,直接用“Response.Content.ReadAsStringAsync()”来获取其中的信息,这样这部分代码所在的部分要用 “async” 标记:

    public override async void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
    {}
  • 相关阅读:
    shell脚本
    恋练有词
    sublime text3 的汉化
    c#中如何将int i=1;转化成string s="0001"
    SQL语句中DateAdd 函数说明
    ASP.NET弹出对话框
    C/C++避免头文件包含造成的重定义方法
    Android:保存图片到Sqlite数据库
    Ubuntu 12.04 配置
    C# 实现天气预报
  • 原文地址:https://www.cnblogs.com/zhurong/p/10077024.html
Copyright © 2011-2022 走看看