Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么HTTP头请求不被routes.MapRoutes()捕获,而HTTP GET被捕获?_C#_Asp.net_.net_Asp.net Mvc_Url Rewriting - Fatal编程技术网

C# 为什么HTTP头请求不被routes.MapRoutes()捕获,而HTTP GET被捕获?

C# 为什么HTTP头请求不被routes.MapRoutes()捕获,而HTTP GET被捕获?,c#,asp.net,.net,asp.net-mvc,url-rewriting,C#,Asp.net,.net,Asp.net Mvc,Url Rewriting,我有一个处理图像请求的.NET控制器 web.config中有一个URL重写规则,用于转换http://localhost/images/1809x1280/image1.jpg 到http://localhost/image/get/image1.jpg/1809/1280 然后我有以下RouteConfig规则 routes.MapRoute() name: "Images", url: "image/get/{filename}/{width}/{h

我有一个处理图像请求的.NET控制器

web.config中有一个URL重写规则,用于转换
http://localhost/images/1809x1280/image1.jpg
到<代码>http://localhost/image/get/image1.jpg/1809/1280

然后我有以下
RouteConfig
规则

    routes.MapRoute()
        name: "Images",
        url: "image/get/{filename}/{width}/{height}",
        defaults: new { controller = "Image", action = "Get" }
    );
当我执行
httpget
请求时,操作被正确地路由到正确的控件,我得到了预期的
HTTP/1.1200ok
响应,但是,当我将HTTP动词从
GET
更改为
HEAD
时,我收到了
HTTP/1.1404未找到
响应

在我的
ImageController.Get()方法中放置了一个断点之后,我注意到只有
httpget
请求击中了它

然后,在
Global.asax.cs
应用程序_BeginRequest
中放置了一个断点,该断点同时被
httpget
httphead
请求击中

当请求是
httphead
时,我拥有
request
对象的以下属性:

RawUrl”/images/1809x1280/image1.jpg“字符串

Url{http://localhost/image/get/image1.jpg/1809/1280}System.Uri

这是正确的,表明重写规则已生效,但从未命中
ImageController.Get()


现在看来,
routes.MapRoute()
似乎有问题,但我不确定如何着手研究它。

显然这比我想象的要简单

我看了所有地方,除了看我的控制器操作,它只装饰了
[HttpGet]
属性,用下面的属性替换它已经修复了它:

[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Head)]
public ActionResult Get(string imageName){
...
}

显然这比我想象的要简单

我看了所有地方,除了看我的控制器操作,它只装饰了
[HttpGet]
属性,用下面的属性替换它已经修复了它:

[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Head)]
public ActionResult Get(string imageName){
...
}

你烤蛋糕,它也吃。。。哈哈哈,看来苏:)你烤蛋糕,它也吃了。。。哈哈哈似乎是苏:)