2015-05-31 18 views
5

Thứ nhất, mọi thứ hoạt động khi tôi chạy nó từ Visual Studio sử dụng iis express.Owin OAuth localhost/Token trả lại 404

Tôi có Api Web Asp.Net đang chạy Owin OAuth. Đây là phần cấu hình của lớp Startup tôi:

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()); 
} 

Đây là Register phần của WebApiConfig.cs

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 } 
    ); 
} 

tôi đã triển khai ứng dụng này trên IIS phiên bản 8.5 * và tôi tất cả mọi thứ công trình trừ localhost/Token endpoint. . Nó là một dự án MVC + Web Api kết hợp.

Tôi đang sử dụng hồ bơi ứng dụng .NET v4.5 (.NET CLR Phiên bản: 4.0) với chế độ đường ống tích hợp và Microsoft.Owin.Host.SystemWeb.dll có trong thư mục bin.

Tại sao tôi nhận được 404 khi tôi thực hiện yêu cầu đến điểm cuối mã thông báo?

+0

Bạn đã đặt 'runAllManagedModulesForAllRequests' thành true như trong [câu trả lời SO này] (http://stackoverflow.com/questions/24101432/configure-an-owin-static-file-server-at-a-specific-route -tiếp đầu ngữ)? –

+0

Có, nó không hoạt động. –

+0

Mọi cập nhật tại đây? –

Trả lời

7

Tôi gặp vấn đề tương tự. Đây là vấn đề của bạn:

#if DEBUG 
    AllowInsecureHttp = true, 
#endif 

cục bộ (IISExpress), bạn đang chạy một DEBUG xây dựng và chỉ thị biên dịch của bạn đặt AllowInsecureHttp để true. Điều này có nghĩa là bạn có thể yêu cầu mã thông báo OAuth mới trên cả http và https.

Triển khai IIS có nghĩa là trước tiên bạn xây dựng RELEASE. Vì vậy, chỉ thị trình biên dịch bỏ qua dòng AllowInsecureHttp. Thuộc tính mặc định là false, có nghĩa là bạn chỉ có thể nhận mã thông báo OAuth qua http s. Nếu bạn thử yêu cầu mã thông báo trên http, máy chủ sẽ trả lời bằng 404.

Các vấn đề liên quan