2016-04-13 5 views
2

ich signalR in Web Api bin Abbilden von folgendem Code in Startup.cs KlasseSignalR 403 Statuscode auf websocket Transport Handshake

public void Configuration(IAppBuilder app) 
    { 

     ConfigureAuth(app); 
     app.Map("/signalr", map => 
     { 
      map.UseCors(CorsOptions.AllowAll); 
      var hubConfiguration = new HubConfiguration 
      { 
       EnableDetailedErrors= true, 
       EnableJSONP=true 
      }; 
      map.RunSignalR(hubConfiguration); 
     }); 
    } 

Zusammen mit ihm verwendet i Bearer-Token-Authentifizierung und Cookies Authentifizierung in Web Api durch folgenden Code

app.UseCookieAuthentication(new CookieAuthenticationOptions 
     { 
      AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, 
      LoginPath = new PathString("/Account/Login"), 
      AuthenticationMode = AuthenticationMode.Active, 
      CookieHttpOnly = true, 
      CookieSecure = CookieSecureOption.SameAsRequest, 
      CookiePath = "/", 
      CookieDomain = "xxxx.cloudapp.net", 
     }); 
     app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); 

     PublicClientId = "self"; 
     OAuthOptions = new OAuthAuthorizationServerOptions 
     { 
      TokenEndpointPath = new PathString("/Token"), 
      Provider = new ApplicationOAuthProvider(PublicClientId), 
      AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"), 
      AccessTokenExpireTimeSpan = TimeSpan.FromDays(14), 
      AllowInsecureHttp = true, 
     }; 

     app.UseOAuthBearerTokens(OAuthOptions); 
     app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions() 
     { 
      Provider = new QueryStringOAuthBearerProvider("Token") 
     }); 

Web Api ist auf verschiedene Domain so i Cors für Api Anrufe aktiviert durch folgenden Code

public static void Register(HttpConfiguration config) 
    { 
     var cors = new EnableCorsAttribute("http://localhost:8080,http://www.myweb.com,http://myweb.com", "*", "*"); 
     cors.SupportsCredentials = true; 
     config.EnableCors(cors); 
    ...... 
    ...... 
    } 

Jetzt, während von Client-Seite verbinden, ich in der Konsole

folgende Störung erhalte ist

SignalR 403 status code

Hier Antwort, dass ich in entsprechend websocket Handshake bin immer auf

enter image description here

Bitte führen Dies.

+0

Vergewissern Sie sich, dass Sie in Ihrer Web API App (Server) einen WebSocket aktiviert/unterstützt haben. –

+0

Es ist in Cloud-Service aktiviert –

+0

nicht sicher, ob dies damit zusammenhängen, aber wenn Sie Framework 4.5 verwenden haben Sie in web.config> appSettings-Tag – Patel

Antwort

0

Ich weiß, dass dies eine alte Frage, aber ich habe das gleiche Problem hatte, so für die Zukunft, wenn jemand stolpert es ...

Irgendwie:

CookieSecure = CookieSecureOption.SameAsRequest, 

das ist Problem. es nicht funktioniert wie es sollte (weiß nicht warum) ...

Dies ist meine Cookie-Konfiguration:

  builder.Register(ctx => new CookieAuthenticationOptions 
      { 
       AuthenticationMode = AuthenticationMode.Active, 
       AuthenticationType = CookieAuthenticationDefaults.AuthenticationType, 
       CookieName = "xxx", 
       CookieHttpOnly = false, // Kako bi mu mogli pristupiti iz Javascripta 
       ExpireTimeSpan = TimeSpan.FromDays(1), 
       LoginPath = PathString.Empty, 
       LogoutPath = PathString.Empty, 
       SlidingExpiration = true, 
#if DEBUG 
       CookieSecure = CookieSecureOption.SameAsRequest, 
#else 
       CookieSecure = CookieSecureOption.Always, 
#endif 
       CookieDomain = "localhost" 
      }); 

und das ist mein Token Konfiguration

  builder.Register(ctx => new OAuthAuthorizationServerOptions 
      { 
       AuthorizeEndpointPath = new PathString("/api/authorize"), 
       TokenEndpointPath = new PathString("/api/token"), 
       ApplicationCanDisplayErrors = true, 
       Provider = ctx.Resolve<ApplicationOAuthProvider>(), 
       //RefreshTokenProvider = ctx.Resolve<ApplicationRefreshTokenProvider>(), 
       AccessTokenExpireTimeSpan = TimeSpan.FromDays(1), 
#if DEBUG 
       AllowInsecureHttp = true 
#endif 
      }); 

Nach Hosting meine Anwendung auf HTTPS localhost es funktioniert automatisch. Warum? Immer noch nicht bekannt: P