gpt4 book ai didi

c# - 为什么 UseStaticFiles 和 UseDefaultFiles 之间的顺序很重要?

转载 作者:行者123 更新时间:2023-11-30 13:43:33 27 4
gpt4 key购买 nike

我理解中间件的注册顺序may matter .然而,这并不是必然如此。

我注意到 UseDefaultFiles() 需要在 UseStaticFiles() 之前(这可以巧妙地被 UseFileServer() 规避)。

我不明白的是为什么。它们是如何碰撞的?!

我已经用谷歌搜索了这个问题,但对于为什么在这个特殊情况下订单很重要的动机为零。只是它很重要......

最佳答案

摘自 Static files in ASP.NET Core 上的文档(在提供默认文档下,有一个重要 注释)。

UseDefaultFiles must be called before UseStaticFiles to serve the default file. UseDefaultFiles is a URL rewriter that doesn't actually serve the file. Enable Static File Middleware via UseStaticFiles to serve the file.

基于此,在提供实际文件 (UseStaticFiles) 之前首先设置 URL 重写器 (UseDefaultFiles) 很重要。
如果不这样做,UseStaticFiles 中间件将首先启动,但对应用程序根目录的请求不会告诉中间件要提供哪个"file"。当您确保首先进行重写时,对应用程序根目录的请求将被重写为对(其中一个)默认文件的请求。

关于c# - 为什么 UseStaticFiles 和 UseDefaultFiles 之间的顺序很重要?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53988848/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com