【问题标题】:WebAPI Autorize Authentication Required PopupWeb API 授权需要验证的弹出窗口
【发布时间】:2015-05-22 13:56:55
【问题描述】:

Webapi 响应状态码 401 时如何禁用 Authentication Required 弹出窗口?



这是我的 webapi 配置

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        // Web API configuration and services

        // Web API routes
        config.MapHttpAttributeRoutes();
        config.SuppressDefaultHostAuthentication();
        config.Filters.Add(new HostAuthenticationFilter(Startup.OAuthOptions.AuthenticationType));

        config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
        config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
        //config.Formatters.JsonFormatter.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;
        config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
    }
}

【问题讨论】:

  • 你试过了吗?你能显示一些代码吗?
  • 哦,是的,我尝试了一整天都没有成功:(
  • 弹出是一种浏览器行为。如果您不想要它,我想您可能必须以自定义方式实现未授权,而不是返回 401,而是返回另一个代码
  • 这确实是浏览器行为,特别是由WWW-Authenticate 标头引起的...大多数浏览器在看到该标头时会自动提示基本身份验证,因此关键是弄清楚如何删除该标头...

标签: asp.net asp.net-mvc authentication asp.net-web-api asp.net-web-api2


【解决方案1】:

转到IIS Manager > Authentication > Basic Authentication 并确保将其设置为Disabled

【讨论】:

  • 这是非常好的提示,我使用的是 iis express,所以我必须在 applicationhost.config 中将 basicAuthentication 更改为 false
猜你喜欢
  • 2017-12-24
  • 1970-01-01
  • 2014-06-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-23
相关资源
最近更新 更多