[{"id":"aspnetcoreintermediate-001","courseId":"aspnet-core-intermediate","domain":"hosting-and-middleware","topic":"Map and MapWhen branching","prompt":"A request to /map1/details reaches app.Map(\"/map1\", ...). Inside that branch, where does the matched /map1 segment go?","hint":"Look at the two path properties on HttpRequest and what each one describes.","explain":"Map runs a branch when the request path starts with a given prefix. Inside the branch, the request carries two path properties that describe the URL in different ways, and each holds different parts.","source":"https://learn.microsoft.com/en-us/aspnet/core/fundamentals/middleware/index","interaction":{"type":"single"},"options":[{"id":"a","text":"Left in Path, with PathBase empty","whyNot":"Map removes the matched segments from Path, so the branch sees only the remainder of the URL."},{"id":"b","text":"Removed from Path and appended to PathBase","why":"Map strips the matched segments from HttpRequest.Path and appends them to HttpRequest.PathBase on each request."},{"id":"c","text":"Copied into PathBase, with Path unchanged","whyNot":"The segments are removed from Path, not copied, so Path no longer contains them."},{"id":"d","text":"Deleted from the request entirely","whyNot":"Nothing is thrown away; the matched segments are kept on HttpRequest.PathBase."}],"answer":"b","explanation":"Map matches a path prefix and, for each request, moves the matched segments from HttpRequest.Path into HttpRequest.PathBase.","concept":"Map matches a path prefix and, for each request, moves the matched segments from HttpRequest.Path into HttpRequest.PathBase.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Inside a Map branch, Path holds only the rest of the URL; the matched prefix moves to PathBase."]},{"id":"aspnetcoreintermediate-002","courseId":"aspnet-core-intermediate","domain":"hosting-and-middleware","topic":"Factory-activated middleware","prompt":"A teammate wraps a factory-activated middleware in UseFactoryActivatedMiddleware(bool option), which calls app.UseMiddleware<FactoryActivatedMiddleware>(option). What happens at runtime?","hint":"Compare which activation path can accept extra arguments: the factory path or convention-based activation.","explain":"UseMiddleware activates middleware in one of two ways: through a factory for IMiddleware types, or by convention. The two paths differ in what arguments they accept.","source":"https://learn.microsoft.com/en-us/aspnet/core/fundamentals/middleware/extensibility","interaction":{"type":"single"},"options":[{"id":"a","text":"The flag is passed through to the constructor","whyNot":"UseMiddleware doesn't forward extra arguments to the constructor of a factory-activated middleware."},{"id":"b","text":"The compiler rejects the call with an error","whyNot":"The problem only appears at runtime, so the code compiles and fails later."},{"id":"c","text":"It throws NotSupportedException at runtime","why":"The factory path can't take extra arguments through UseMiddleware, so the call throws when it runs."},{"id":"d","text":"The flag is silently ignored and defaults apply","whyNot":"The call doesn't fall back to defaults; passing the argument makes it throw."}],"answer":"c","explanation":"Middleware activated through IMiddleware can't receive extra arguments via UseMiddleware; passing one throws NotSupportedException at runtime.","concept":"Middleware activated through IMiddleware can't receive extra arguments via UseMiddleware; passing one throws NotSupportedException at runtime.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["IMiddleware gives per-request scoped services, but UseMiddleware can't pass it custom arguments."]},{"id":"aspnetcoreintermediate-003","courseId":"aspnet-core-intermediate","domain":"hosting-and-middleware","topic":"Forwarded headers behind proxies","prompt":"With WebApplication, app.UseRouting() must be called after app.UsePathBase(\"/foo\") so that routing matches the rewritten path.","hint":"Think about which middleware needs to see the path after the proxy prefix has been removed.","explain":"UsePathBase splits a proxy's app base path from the rest of the request path. Routing chooses an endpoint by reading the path, so the order of these middleware changes which path it reads.","source":"https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","why":"UsePathBase has to rewrite the path first; routing that ran earlier would match the unstripped path."},{"id":"b","text":"False","whyNot":"Routing matches whatever path it sees, so if it ran first it would match before the rewrite."}],"answer":"a","explanation":"UsePathBase moves a proxy's app base path into Request.PathBase; with WebApplication, UseRouting must come after it so routes match the rewritten Path.","concept":"UsePathBase moves a proxy's app base path into Request.PathBase; with WebApplication, UseRouting must come after it so routes match the rewritten Path.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Call UsePathBase before UseRouting, or routes are matched against the path before it is rewritten."]},{"id":"aspnetcoreintermediate-004","courseId":"aspnet-core-intermediate","domain":"hosting-and-middleware","topic":"BackgroundService long-running work","prompt":"A hosted service's StartAsync contains a loop that runs for hours before it returns. What is the main problem with that?","hint":"Think about how the host runs hosted services when it starts the app.","explain":"A hosted service has a start method the host awaits during startup, plus a method for work that runs over the service's lifetime. The host activates each service once.","source":"https://learn.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services","interaction":{"type":"single"},"options":[{"id":"a","text":"The service restarts each time a request arrives","whyNot":"A hosted service is activated once at app startup and gracefully shut down at app shutdown, not per request."},{"id":"b","text":"Later hosted services wait until this one finishes starting","why":"Hosted services run one after another, and no further services start until StartAsync runs to completion."},{"id":"c","text":"The loop is moved into Dispose, which runs at startup","whyNot":"Dispose is for releasing resources and runs at shutdown; long-running work belongs in ExecuteAsync."},{"id":"d","text":"The host cancels the loop as soon as the server starts","whyNot":"Cancellation is triggered by StopAsync at shutdown, not by the server starting."}],"answer":"b","explanation":"Hosted services start sequentially, so StartAsync should only do short work; long-running loops belong in ExecuteAsync.","concept":"Hosted services start sequentially, so StartAsync should only do short work; long-running loops belong in ExecuteAsync.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Keep StartAsync short; long-running loops belong in ExecuteAsync."]},{"id":"aspnetcoreintermediate-005","courseId":"aspnet-core-intermediate","domain":"hosting-and-middleware","topic":"Middleware order in the pipeline","prompt":"A web app adds HTTPS redirection, static files, routing, authentication and authorization middleware. In what order does a request pass through them in the common ASP.NET Core setup?","hint":"Think about which middleware must act on the request before any file or endpoint is picked.","explain":"Middleware runs in pipeline order, and a piece that answers a request early stops the later pieces from seeing it. Where each piece sits depends on what it needs to know about the request.","source":"https://learn.microsoft.com/en-us/aspnet/core/fundamentals/middleware/","interaction":{"type":"sort","items":[{"text":"HTTPS redirection","why":"It redirects HTTP requests to HTTPS and sits ahead of static files and routing."},{"text":"Static files","why":"It returns static files and short-circuits further request processing, so later middleware doesn't run for those requests."},{"text":"Routing","why":"It matches the request to an endpoint; authentication is added immediately after it."},{"text":"Authentication","why":"It attempts to authenticate the user before they're allowed access to secure resources."},{"text":"Authorization","why":"It authorizes the user to access secure resources, so it comes after authentication has identified them."}]},"options":[],"answer":"o:abcde","explanation":"The common middleware order runs HTTPS redirection, then static files, then routing, then authentication, then authorization. The order in Program.cs sets the order a request passes through them.","concept":"The common middleware order runs HTTPS redirection, then static files, then routing, then authentication, then authorization. The order in Program.cs sets the order a request passes through them.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Middleware runs in the order you register it in Program.cs, so each position decides what that piece sees."]}]