Owin OAuth localhost / Token返回404
首先,当我使用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.cs
的Register
部分
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"); 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),并且bin文件夹中存在Microsoft.Owin.Host.SystemWeb.dll
。
当我向令牌端点发出请求时,为什么会得到404?
我遇到过同样的问题。 这是你的问题:
#if DEBUG AllowInsecureHttp = true, #endif
在本地(IISExpress),您正在运行DEBUG构建,并且您的编译器指令将AllowInsecureHttp
设置为true
。 这意味着您可以通过http和https请求新的OAuth令牌。
部署到IIS意味着您首先执行RELEASE构建。 因此编译器指令省略了AllowInsecureHttp
行。 该属性默认为false
,这意味着您只能通过http获取OAuth令牌。 如果您尝试通过http询问令牌,服务器将使用404
回答。