自托管Owin,静态文件和身份验证

时间:2014-10-24 15:14:08

标签: azure asp.net-identity owin

我需要在Azure辅助角色中嵌入一个小的Owin主机。 我需要提供一些静态文件,但子目录应该受密码保护。我无法通过身份验证在自托管应用上找到任何好的示例。

我正在尝试设置以下appBuilder:

Func<CookieValidateIdentityContext, Task> validate = async context =>
            {
                Logger.Trace("Access");
            };
        var authOptions = new CookieAuthenticationOptions
                              {
                                  AuthenticationMode = AuthenticationMode.Active,
                                  AuthenticationType =
                                      DefaultAuthenticationTypes.ApplicationCookie,
                                  LoginPath = new PathString("/Login.html"),
                                  Provider =
                                      new CookieAuthenticationProvider
                                          {
                                              OnValidateIdentity
                                                  = validate,
                                                  OnApplyRedirect = redirect,
                                                  OnResponseSignIn = signIn
                                          }
                              };
        appBuilder.UseCookieAuthentication(authOptions);
        appBuilder.UseStageMarker(PipelineStage.Authenticate);
        var basePath = GetBasePath();
        var webPath = Path.Combine(basePath, "Web");
        var physicalFileSystem = new PhysicalFileSystem(webPath);
        var options = new FileServerOptions
                          {
                              EnableDefaultFiles = true,
                              EnableDirectoryBrowsing = true,
                              FileSystem = physicalFileSystem
                          };
        options.StaticFileOptions.FileSystem = physicalFileSystem;
        options.StaticFileOptions.ServeUnknownFileTypes = true;
        options.DefaultFilesOptions.DefaultFileNames = new[] { "index.html" };
        appBuilder.UseFileServer(options);

我遇到两个问题:

  • 永远不会遇到Logger.Trace(&#34; Access&#34;)断点
  • 我应该如何定义Login.html页面?它应该包含表格吗?但是我该如何处理后期行动?

0 个答案:

没有答案