2016-12-22 33 views
3

當我嘗試使用我的應用程序登錄時,我遇到了很大的性能問題。該應用程序是Azure中託管的Web api應用程序。我使用反應js作爲我的前端。OWIN登錄性能緩慢> 30秒

而在我的SimpleAuthorizationProvider中,我提取用戶並向ClaimsIdentity屬性添加聲明。如果我在本地調試它,我第一次登錄時只有慢速性能問題,但下次登錄登錄時即時訪問。當我將它上傳到Azure的測試環境時,問題就出在了每個請求上。

我已經開啓了Azure中的「始終開啓」屬性以供網絡應用使用。我已超時請求,並且需要花費很多時間的事情是這一段代碼在SimpleAuthorizationprovider

context.Validated(ticket); 

它發生在我的測試環境15瑞典克朗,只是授權用戶。我的前端也可能有一些延遲。在我的前端,我們使用superagent向web api發出請求。

這裏是我的配置,我的啓動類:

public void Configuration(IAppBuilder app) 
    { 
     app.UseCors(CorsOptions.AllowAll); 

     ConfigureOAuth(app); 
     var physicalFileSystem = new PhysicalFileSystem(@"./Html"); 
     var options = new FileServerOptions 
     { 
      EnableDefaultFiles = true, 
      FileSystem = physicalFileSystem, 
      StaticFileOptions = 
      { 
       FileSystem = physicalFileSystem, 
       ServeUnknownFileTypes = true 
      }, 
      DefaultFilesOptions = {DefaultFileNames = new[] {"Startup.html"}} 
     }; 
     app.UseFileServer(options); 

     // Get your HttpConfiguration. 
     var config = GetInjectionConfiguration(); 
     config.MessageHandlers.Add(new QueryStringBearerToken()); 

     WebApiConfig.Register(config); 

     // Setup WebApi 
     app.UseWebApi(config); 
     SetupWebApi(config); 

     Application_Start(config); 
     config.EnsureInitialized(); 
    } 

    public void ConfigureOAuth(IAppBuilder app) 
    { 
     var oAuthServerOptions = new OAuthAuthorizationServerOptions 
     { 
      TokenEndpointPath = new PathString("/api/token"), 
      AuthorizeEndpointPath = new PathString("/Login"), 
      AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(120), 
      Provider = new SimpleAuthorizationServerProvider(), 
      RefreshTokenProvider = new ApplicationRefreshTokenProvider(), 
      AllowInsecureHttp = true, 

     }; 

     var oAuthBearerOptions = new OAuthBearerAuthenticationOptions 
     { 
      Provider = new QueryStringOAuthBearerProvider(), 
      AccessTokenProvider = new AuthenticationTokenProvider(), 
     }; 

     app.UseOAuthBearerAuthentication(oAuthBearerOptions); 
     app.UseOAuthAuthorizationServer(oAuthServerOptions); 
    } 

編輯:

我現在可以說的是,context.validated(門票)是沒有問題的。我已將Azure中的應用程序見解連接起來,以查看是否可以從那裏獲得更多有用的信息。我的猜測仍然是,在請求點擊之前,api進程並沒有「加熱」,並且導致進程需要每次都提高。當我在本地進行調試時,第一次請求打開我的令牌端點需要大約10秒的時間。之後,我發送了另一個請求,一切按預期工作。一些更多的挖掘需要在這裏完成;)

回答

0

問題是基類AuthContext給了連接字符串名稱AuthContext,但在我的webconfig中,我的連接字符串被賦予名稱Default,所以當應用程序啓動時,第一個5或6請求只是彈起了,因爲沒有與數據庫的有效連接。

因此,這裏是我的解決方案

public AuthContext() 
      : base("Default") 
     { 

     } 
0

您是否嘗試遠程調試?您必須在Azure門戶中的Azure Web App上啓用此功能,然後從Visual Studio中通過Cloud Explorer找到您的Web App並選擇遠程調試。確保您以調試模式發佈了您的網站。

也許這可以幫助您找出問題所在。

+0

奧基我會努力做到這一點。希望我會找到一些答案。 –

0

我不明白爲什麼你需要

的Application_Start(配置); config.EnsureInitialized();

在您的配置中。請刪除這個。

+0

請詳細說明爲什麼你認爲我應該刪除它? Application_Start方法註冊所有依賴關係,並且config.ensureInitilialized確保所有依賴關係都已正確註冊。你認爲這與表演有什麼關係? –