OWIN登录慢性能> 30秒

And*_*alk 5 c# azure superagent owin

当我尝试使用我的应用程序登录时,我遇到了很大的性能问题.该应用程序是Azure中托管的Web api应用程序.我使用反应js作为我的前端.

在我的SimpleAuthorizationprovider中,我将获取用户并向ClaimsIdentity属性添加声明.如果我在本地调试它我第一次登录时只有慢速性能问题,但下次登录登录时是即时访问.当我将它上传到Azure中的测试环境时,每个请求都存在问题.

我已经在Azure中为Web应用程序启用了"Always on"属性.我有时间请求和需要花费很多时间的东西是SimpleAuthorizationprovider中的这段代码

  context.Validated(ticket);
Run Code Online (Sandbox Code Playgroud)

它需要我的测试环境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);
    }
Run Code Online (Sandbox Code Playgroud)

编辑:

我现在可以说context.validated(ticket)不是问题.我已经在Azure中连接了应用程序见解,看看我是否可以从那里获得更多有用的信息.我的猜测仍然是api进程在请求命中之前没有"加热",导致进程需要每次都提升.当我在本地调试它时,第一个请求命中我的令牌端点需要大约10 sek.在那个请求后我发送了另一个,一切都按预期工作.在这里需要做更多的挖掘工作;)

And*_*alk 1

问题是基类 AuthContext 已为连接字符串指定了名称 AuthContext,但在我的 webconfig 中,我的连接字符串被指定为名称 Default,因此当应用程序启动时,前 5 个或 6 个请求只是反弹,因为没有到该连接的有效连接数据库。

所以这是我的解决方案

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

        }
Run Code Online (Sandbox Code Playgroud)