當我嘗試使用我的應用程序登錄時,我遇到了很大的性能問題。該應用程序是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秒的時間。之後,我發送了另一個請求,一切按預期工作。一些更多的挖掘需要在這裏完成;)
奧基我會努力做到這一點。希望我會找到一些答案。 –