【问题标题】:Owin OAuth localhost/Token returns 404Owin OAuth 本地主机/令牌返回 404
【发布时间】:2015-08-14 08:10:59
【问题描述】:

首先,当我使用 iis express 从 Visual Studio 运行它时,一切正常。

我有一个运行 Owin OAuth 的 Asp.Net Web Api。这是我Startup类的配置部分:

private static void ConfigureAuth(IAppBuilder app)
{
    var oAuthOptions = new OAuthAuthorizationServerOptions
    {
    #if DEBUG
        AllowInsecureHttp = true,
    #endif
        TokenEndpointPath = new PathString("/Token"),
        AccessTokenExpireTimeSpan = TimeSpan.FromDays(30),
        Provider = new ApplicationOAuthProvider()
    };

    app.UseOAuthAuthorizationServer(oAuthOptions);
    app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
}

这是我的WebApiConfig.csRegister 部分

public static void Register(HttpConfiguration config)
{
    // Web API configuration and services
    config.SuppressDefaultHostAuthentication();
    config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

    var cors = new EnableCorsAttribute("*", "*", "*");
    config.EnableCors(cors);

    // Web API routes
    config.MapHttpAttributeRoutes();

    // OData
    var builder = new ODataConventionModelBuilder();
    builder.EntitySet<Employee>("Employee");
    config.MapODataServiceRoute(
        routeName: "ODataRoute",
        routePrefix: "odata/",
        model: builder.GetEdmModel()
    );

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

我已经在 IIS 版本 8.5.* 上部署了这个应用程序,除了localhost/Token 端点外,一切正常。它是一个结合 MVC + Web Api 的项目。

我正在使用具有集成管道模式的 .NET v4.5 应用程序池(.NET CLR 版本:4.0),并且 Microsoft.Owin.Host.SystemWeb.dll 存在于 bin 文件夹中。

为什么我向 Token 端点发出请求时得到 404?

【问题讨论】:

  • 您是否像 this SO answer 一样将 runAllManagedModulesForAllRequests 设置为 true?
  • 是的,它也不起作用。
  • 我会尽快发布更新
  • 找到任何解决方案?...请更新我们
  • 尝试在 web.config 中添加

标签: c# asp.net .net iis


【解决方案1】:

我有同样的问题。这是你的问题:

#if DEBUG
    AllowInsecureHttp = true,
#endif

在本地 (IISExpress),您正在运行 DEBUG 构建,并且您的编译器指令将 AllowInsecureHttp 设置为 true。这意味着您可以通过 http 和 https 请求新的 OAuth 令牌。

部署到 IIS 意味着您首先进行 RELEASE 构建。所以编译器指令省略了AllowInsecureHttp 行。该属性默认为false,这意味着您只能通过 https 获取 OAuth 令牌。如果您尝试通过 http 请求令牌,服务器将回复 404

【讨论】:

    【解决方案2】:

    安装 Nuget 包 Microsoft.Owin.Host.SystemWeb,因为您的处理程序未注册。

    如果仍然无法正常工作,则在 web.config 文件中添加以下处理程序

      <add name="Owin" verb="" path="*" type="Microsoft.Owin.Host.SystemWeb.OwinHttpHandler, Microsoft.Owin.Host.SystemWeb"/>
    
    
    </handlers>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-10
      • 2017-12-24
      • 2015-07-02
      • 2019-10-07
      • 2023-03-05
      • 1970-01-01
      • 2012-08-19
      • 1970-01-01
      相关资源
      最近更新 更多