当我尝试使用应用程序登录时,我有一个很大的性能问题。该应用程序是Azure托管的Web API应用程序。我将React JS用于我的前端。
,在我的SimpleAuthorization -Provider中,我正在获取用户并将索赔添加到索赔属性属性中。如果我在本地进行调试,我只在第一次登录时就有缓慢的性能问题,但是下次登录时,登录为即时访问。当我将其上传到Azure的测试环境时,问题是每个请求。
我已经打开了Web应用中Azure中的"始终开"属性。我已经计时了请求,而花费大量时间的事情是SimpleAuthorization Provider中的这个代码
context.Validated(ticket);
它需要在我的测试环境中15 sek来授权用户。我的前端也可能有一些延误。在我的前端,我们正在使用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 sek。在此请求之后,我发送了另一个,一切都按预期工作。需要在这里进行一些更多的挖掘;)
问题是基类authcontext给出了connectionsTring in authcontext名称,但是在我的webconconfig中给出了我的connectionstring,因此给出了名称默认值,因此当应用程序启动时,第一个5或6个请求只是弹跳是因为与数据库没有有效的连接。
所以这是我的解决方案
public AuthContext()
: base("Default")
{
}
您是否尝试远程调试?您必须在Azure Portal的Azure Web应用程序上启用此功能,然后在Visual Studio中使用Cloud Explorer查找您的Web应用程序,然后选择用于远程调试。确保您以调试模式发布了网站。
也许这可以帮助您查明问题。
我不明白你为什么需要
application_start(config);config.ensureInitialized();
在您的配置中。请删除此。