WebGet UriTemplate 在点 ('.'/%2E) 上失败? [英] WebGet UriTemplate fails on dot ('.'/%2E)?

查看:37
本文介绍了WebGet UriTemplate 在点 ('.'/%2E) 上失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了一段时间来弄清楚为什么这个 UriTemplate 不能作为 WCF 服务的一部分工作并且似乎无法到达任何地方:

I've been trying for a while now to figure out why this UriTemplate does not work as part of a WCF service and can't seem to get anywhere:

[WebGet(UriTemplate="api/1.0/version")]
string GetVersion();

快速测试表明 UrlTemplateTable 匹配得很好(输出为api/1.0/version"):

A quick test shows that UrlTemplateTable matches it fine (output is 'api/1.0/version'):

static void Main(string[] args)
{
    Uri prefix = new Uri("http://localhost/");
    System.UriTemplateTable table = new System.UriTemplateTable(prefix);
    table.KeyValuePairs.Add(new KeyValuePair<UriTemplate, Object>(new UriTemplate("api/1.0/version"), "a"));
    table.KeyValuePairs.Add(new KeyValuePair<UriTemplate, Object>(new UriTemplate("api/2.0/version"), "b"));
    table.KeyValuePairs.Add(new KeyValuePair<UriTemplate, Object>(new UriTemplate("api/version"), "c"));

    Uri uri = new Uri("http://localhost/api/1.0/version");
    UriTemplateMatch match = table.MatchSingle(uri);
    Console.WriteLine("{0}", match.Template.ToString());
}

点不是 URL 中的非法字符,RequestPathInvalidCharacters 不排除它,没有可能干扰的重写规则.在它的文档中也找不到任何内容.

The dot is not an illegal character in URLs, RequestPathInvalidCharacters does not exclude it, there are no rewrite rules in place that could interfere. Couldn't find anything in the documentation on it either.

虽然有一个明显的解决方法,不要在模板中使用点,但我很好奇为什么它会失败并显示HTTP 404/找不到资源".

While there is an obvious workaround, not use the dot in the template, I'm curious as to why it fails with 'HTTP 404/The resource cannot be found'.

推荐答案

我之前也遇到过同样的问题.我意识到这是 IIS 中的限制,与 WCF 无关.当 IIS 最初拦截请求时,会假定 .代表一个扩展,因此它尝试为该扩展找到一个托管处理程序.由于它没有找到任何,它只是抛出一个 404.

I ran into the same issue before. I realized it was a limitation in IIS, and nothing to do with WCF. When IIS initially intercepts the request assumes the value following the . represents an extension, so it tries to find a managed handler for that extension. Since it does not find any, it just throws a 404.

问候巴勃罗.

这篇关于WebGet UriTemplate 在点 ('.'/%2E) 上失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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