ASP.NET突然想要一个斜杠 [英] ASP.NET suddenly wants a trailing slash

查看:120
本文介绍了ASP.NET突然想要一个斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ASP.NET应用程序中,我们有很多(认为是几十个)控制器类,例如:

  [ RoutePrefix( some / thing / 1.0)] 
公共类SomeController:ApiController
{
[HttpGet]
[Route()]
公共字符串GetInfo ()
{
返回 hello world;
}

[HttpPut]
[Route()]
public void StoreInfo(字符串信息)
{
// //。 ..
}
}

这已经好几个星期了,没有任何问题。我们可以将这些端点称为:

  GET https://myWebApp/client/some/thing/1.0 

现在,由于昨天的夜间构建,此功能已停止工作。突然,我们只能使用斜杠访问这些URL,即

  GET https:// myWebApp / client / some / thing /1.0/ 

这也适用于参数化查询:

 获取https://myWebApp/client/some/thing/1.0?x = 42 

不再工作,但

  GET https:// myWebApp /客户/某物/某物/1.0/?x=42 

有。



由于上一次工作的构建只有一天,所以我扫描了源代码管理的提交历史记录,并比较了构建包。我找不到与该问题有关的任何更改。



此外,这肯定与我们应用程序中的某些更改有关:我可以重现该问题将我的二进制文件更新为昨天构建的二进制文件之后,就在应用程序的本地副本上保存了。 (请注意,今天早上已经创建了另一个构建,而问题仍然存在。因此,并不是昨天的构建以某种方式被破坏;所做的任何更改似乎都是永久的。)



可能发生了什么变化,我还能去哪里寻找它?



或者,更主动地问:



在哪里可以更改此行为?

解决方案

我们发现了为什么现在开始出现错误的具体原因:



MapSignalR 的调用已被注释如果没有它,则埋在应用程序配置文件中某个地方的更旧的,可能是错误的设置变为活动状态:
一个 TransferRequestHandler ,其路径指定为 *。而不只是 *



大概是SignalR以某种方式覆盖了该设置一经初始化,因此问题在过去几年中从未出现过。 p>

因此,明确地: Web.config 文件包含以下行:

 < add name = ExtensionlessUrlHandler-Integrated-4.0 path = *。动词= * type = System.Web.Handlers.TransferRequestHandler preCondition = integratedMode,runtimeVersionv4.0 /> 

必须更改为

 < add name = ExtensionlessUrlHandler-Integrated-4.0 path = * verb = * type = System.Web.Handlers.TransferRequestHandler preCondition = integratedMode,runtimeVersionv4.0  /> 

此处描述的问题将消失。



(不幸的是,此解决方案导致另一个问题。 )


In an ASP.NET application, we have plenty (think, several dozen) of controller classes like this:

[RoutePrefix("some/thing/1.0")]
public class SomeController : ApiController
{
    [HttpGet]
    [Route("")]
    public string GetInfo()
    {
        return "hello world";
    }

    [HttpPut]
    [Route("")]
    public void StoreInfo(string info)
    {
        // ...
    }
}

This has been working fine for some weeks, without any issues. We could call those endpoints as follows:

GET https://myWebApp/client/some/thing/1.0

Now, with yesterday's nightly build, this has stopped working. Suddenly, we can only access those URLs with a trailing slash, i.e.

GET https://myWebApp/client/some/thing/1.0/

This applies to parametrized queries, as well:

GET https://myWebApp/client/some/thing/1.0?x=42

doesn't work anymore, but

GET https://myWebApp/client/some/thing/1.0/?x=42

does.

As the last working build is just one day back, I have scanned the commit history of our source control, and I have compared the build packages side by side. I was not able to find any change that seemed to be related to this issue.

Moreover, this is definitely related to some change in our application: I could reproduce the issue on my local copy of the application exactly after updating my binaries to those of yesterday's build. (Note that another build has been created this morning, and the issue is still there. So, it's not that yesterday's build was broken in some way; whatever has changed seems to be permanent.)

What could have changed and where else could I go looking for it?

Or, asked more proactively:

Where can I change this behaviour?

解决方案

We have found the concrete cause of why the error started appearing now:

A call to MapSignalR had been commented out, and without it, a much older, presumably erroneous setting buried somewhere in the application's configuration files became active: A TransferRequestHandler whose path was specified as *. instead of just *.

Presumably, SignalR somehow overwrites that setting once initialized, so the issue never popped up for the past couple of years.

So, explicitly: The Web.config file contained the following line:

<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>

This had to be changed to

<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*" verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>

for the issue described here to go away.

(Unfortunately, this solution causes another problem.)

这篇关于ASP.NET突然想要一个斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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