我希望有一个名为“properties”的路由,但收到 404 错误(检测磁盘上存在文件夹)
我会尝试简单地说,当我尝试创建名称和 url 为 properties
的自定义路由时,我发现我的 ASP.NET MVC 应用程序在点击路由时返回未找到的 404 文件。
我推断这很可能是由于我在磁盘上有一个名为 Properties 的文件夹引起的,它当然是自动创建的常见 asp.net 文件夹。我发现其他人也遭受过 这个问题在SO上,但看起来还没有解决方案,只是将你的路线命名为不同的东西!
这肯定是一个疏忽,还是必须有解决方法?显然,您可能需要许多通用目录作为可互换的路由和/或文件夹,其中一些我们已经知道的目录(例如属性)可能无法删除!我也知道我们也需要将真实文件夹视为 URL,但我认为在查看磁盘上的文件夹之前应该优先考虑路由。
如果有人对如何实现这一目标有任何想法,我们将不胜感激。 :)
I will try and be brief, I am finding when trying to create a custom route with a name and url of properties
that my ASP.NET MVC app is returning a 404 file not found when hitting the route.
I have deduced this down to most likely be caused by the fact I have a folder on disk called Properties which is of course a common asp.net folder which is automatically created. I have found someone else who has suffered from this problem on SO, but looks like there has been no resolution, only to name your route something different!
Surely this is an oversight, or there must be a workaround? Obviously there will be many common directories you may need as routes and/or folders interchangeably, some of which we already know like Properties probably can't be deleted! I also understand we need to honor real folders as URLs too, but I feel routing should take priority before looking at folders on disk.
If someone has any ideas on how to accomplish this it would be greatly appreciated. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 .NET 参考源代码,
Properties
似乎并不是 ASP.NET 运行时所特有的(HttpRuntime.cs
具有的字符串常量) bin
、App_Code
等)。尝试将物理
Properties
文件夹重命名为App_Properties
之类的名称,并编辑其中文件的命名空间以匹配。您还需要编辑.csproj
/.vbproj
文件,因为 VS 隐藏了这个“特殊”文件夹的重命名命令。完成此操作后,使用项目属性选项卡中的一些内置行为(例如创建默认设置和资源)将导致重新创建
Properties
文件夹,因此您必须打开直接编辑.settings
和.resx
文件。Looking at the .NET reference source code, it doesn't appear as if
Properties
is special to the ASP.NET runtime (HttpRuntime.cs
has string constants forbin
,App_Code
, etc.).Try renaming the physical
Properties
folder to something likeApp_Properties
and editing the namespace of the files in there to match. You'll also need to edit the.csproj
/.vbproj
file too, since VS hides the Rename command for this "special" folder.Once you've done this, using some of the built-in behaviour in the project property tabs such as creating default settings and resources will cause the
Properties
folder to be recreated so you'll have to open the.settings
and.resx
files directly to edit them.如果删除 ASP.NET MVC 项目中的属性文件夹,它将按描述的方式工作。
应该注意的是,您所描述的行为在 IIS 下运行时不会出现(这实际上并不是一个解决方案)。
IISExpress 发布后应该会有所帮助!
我想对此进行更多实验,因为我认为路由引擎优先于文件系统对象,特别是当您设置通配符映射时。
If you remove the properties folder in your asp.net mvc project it will work as described.
It should be noted that the behavior you are describing will not present itself when running under IIS (not that this is actually a solution).
IISExpress should help when it is released!
I would like to experiment with this more as I thought the route engine took precedence over file system objects, esp when you setup a wild card mapping.