Skip to content

src/security/samples/StaticFilesAuth always not working  #43274

Closed
@hylinux

Description

@hylinux

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Hi, When I tried to run the sample in : src/Security/Sampels/StaticFilesAuth, look like it was broken. would you help us take a look?

when I tried to run the sample, after login, access the url: /https://localhost:5001/MapAuthenticatedFiles

it willreport Exception:

System.InvalidOperationException: The request reached the end of the pipeline without executing the endpoint: '/'. Please register the EndpointMiddleware using 'IApplicationBuilder.UseEndpoints(...)' if using routing.
   at Microsoft.AspNetCore.Builder.ApplicationBuilder.<>c.<Build>b__18_0(HttpContext context)
   at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.StaticFiles.DirectoryBrowserMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.StaticFiles.DefaultFilesMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authorization.Policy.AuthorizationMiddlewareResultHandler.HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.InvokeCore(HttpContext context, PathString matchedPath, PathString remainingPath)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

I tried to debug into.
I found it will jump here:

      app.Map("/MapAuthenticatedFiles", branch =>
        {
            branch.Use((context, next) => { SetFileEndpoint(context, files, null); return next(context); });
            branch.UseAuthorization();
            SetupFileServer(branch, files);
        });

the werid thing is: it will run into branch.Use( (context, next) => {} ), and then the pipeline was end, will not go through

           branch.UseAuthorization();
            SetupFileServer(branch, files);

would you help to take a look?

thanks

Expected Behavior

it should work success

Steps To Reproduce

No response

Exceptions (if any)

System.InvalidOperationException: The request reached the end of the pipeline without executing the endpoint: '/'. Please register the EndpointMiddleware using 'IApplicationBuilder.UseEndpoints(...)' if using routing.
at Microsoft.AspNetCore.Builder.ApplicationBuilder.<>c.b__18_0(HttpContext context)
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.StaticFiles.DirectoryBrowserMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.StaticFiles.DefaultFilesMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authorization.Policy.AuthorizationMiddlewareResultHandler.HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.InvokeCore(HttpContext context, PathString matchedPath, PathString remainingPath)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

.NET Version

6.0.400

Anything else?

No response

Metadata

Metadata

Assignees

Labels

area-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsinvestigate

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions