2

I need to embed a small Owin host in an Azure worker Role. I need to serve some static files, but a sub-directory should be password-protected. I couldn't find any good example on self-hosted apps with authentication.

I'm trying to setup the following 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);

I'm stuck with two problems:

  • The Logger.Trace("Access") breakpoint is never hit
  • How should I define the Login.html page? Should it contain a form? But how can I handle the post action?
fra
  • 3,488
  • 5
  • 38
  • 61

0 Answers0