ASP.NET路由:令牌,和路线值之间立即子片段与从文字子片段的文字 [英] ASP.NET routing: Literal sub-segment between tokens, and route values with a character from the literal sub-segment

查看:86
本文介绍了ASP.NET路由:令牌,和路线值之间立即子片段与从文字子片段的文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我问的原因是因为IIS保护某些ASP.NET文件夹,如斌的App_Data,APP_ code,等等。即使URL没有映射到一个实际的文件系统文件夹IIS拒绝一个网址路径段等于提到的名字之一。

The reason I'm asking is because IIS protects certain ASP.NET folders, like Bin, App_Data, App_Code, etc. Even if the URL does not map to an actual file system folder IIS rejects a URL with a path segment equal to one of the mentioned names.

这意味着我不能有一个这样的路线:

This means I cannot have a route like this:

{controller}/{action}/{id}

...其中ID可以是任何字符串例如。

... where id can be any string e.g.

Catalog/Product/Bin

因此​​,而不是禁用此安全措施,我愿意改变路线,ID使用前后缀,像这样的:

So, instead of disabling this security measure I'm willing to change the route, using a suffix before the id, like these:

{controller}/{action}_{id} // e.g. Catalog/Product_Bin
{controller}/{action}/_{id} // e.g. Catalog/Product/_Bin

但是,如果该ID包含新的定界符,航线将不起作用_在这种情况下,例如

But these routes won't work if the id contains the new delimeter, _ in this case, e.g.

// These URL won't work (I get 404 response)
Catalog/Product_Bin_
Catalog/Product/_Bin_
Catalog/Product/__Bin

为什么呢?我不知道,看起来像我的错误。我怎样才能让这些路线工作,其中ID可以是任何字符串?

Why? I don't know, looks like a bug to me. How can I make these routes work, where id can be any string?

推荐答案

好吧,我有一个明确的答案。是的,这是一个错误。然而,在这一点上我很遗憾地说,我们没有计划来解决它的一对夫妇的原因:

Ok, I have a definitive answer. Yes, this is a bug. However, at this point I regret to say we have no plans to fix it for a couple of reasons:


  • 这是一个重大更改,并可能是一个非常难以察觉一家这样。

  • 有一个简单的解决方法。

你可以做的是改变的URL没有下划线:

What you can do is change the URL to not have the underscore:

{controller}/{action}/_{id}

然后添加需要的ID参数以下划线字符开头的路由约束。

Then add a route constraint that requires that the ID parameter starts with an underscore character.

那么你的操作方法中,你剪掉从id参数下划线preFIX。你甚至可以写一个动作过滤器,如果你喜欢为你做这个。很抱歉给您带来的不便。

Then within your action method you trim off the underscore prefix from the id parameter. You could even write an action filter to do this for you if you liked. Sorry for the inconvenience.

这篇关于ASP.NET路由:令牌,和路线值之间立即子片段与从文字子片段的文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆