为什么我的 http 响应正文突然包含大量乱码?

发布于 2024-08-15 08:00:59 字数 825 浏览 5 评论 0原文

我正在尝试重构现有的 asp.net-mvc Web 应用程序并引入 mvc-turbine。
该应用程序按原样工作,但我想让它更具可插拔性和可维护性,以便将来的维护会更容易。

我想我应该尽量保持重构步骤尽可能小,所以我引用了 MvcTurbine、MvcTurbine.Unity 和 MvcTurbine.Web。
然后我在 global.asax.cs 中使我的 MvcApplication 看起来像这样:

Public class MvcApplicatoin : TurbineApplication{
    static MvcApplication(){
        ServiceLocatorManager.SetLocatorProvider(() => new UnityServiceLocator());
        Application_Start();
    }
    <snip of all code that hasn't changed/>
}

我意识到调用 Application_Start 并不是它应该如何进行,但这将使第一步的更改尽可能小。
当我现在运行时,我看到控制器中的代码被命中并正确运行。然后我的观点就被呈现了。我可以单步执行每一行,也没有问题。然后结果会显示在浏览器中:乱码。
������í½I%&/mÊ{JõJ×àt¡$Ø@ìÁÍæìiG#)«*ÊeVe]f@Ìí¼÷Þ{ï½÷Þ
等等,整整一页。

在没有 Turbine 的情况下我没有遇到这个问题,在之前的测试中我也没有遇到任何问题,从一开始就引入 Turbine。
关于如何开始调试这个有什么想法吗?

I'm trying to refactor an existing asp.net-mvc web application and introduce mvc-turbine.
The application works as is, but I want to make it more pluggable and maintainable so future maintenance will be easier.

I figured I'd try to keep the refactoring steps as small as possible, so I referenced MvcTurbine, MvcTurbine.Unity and MvcTurbine.Web.
Then I made my MvcApplication in global.asax.cs look like this:

Public class MvcApplicatoin : TurbineApplication{
    static MvcApplication(){
        ServiceLocatorManager.SetLocatorProvider(() => new UnityServiceLocator());
        Application_Start();
    }
    <snip of all code that hasn't changed/>
}

I realize calling Application_Start is not how it's supposed to go, but that would keep the changes for the first step as small as possible.
When I now run, I see the code in my controller gets hit and runs correctly. Then my views are being rendered. I can step through each line, no problems there either. And then the result gets shown in the browser: gibberish.
������í½I%&/mÊ{JõJ×àt¡$Ø@ìÁÍæìiG#)«*ÊeVe]f@Ìí¼÷Þ{ï½÷Þ
etc, a whole page of that.

I didn't encounter this problem without Turbine nor did I encounter any problems in previous tests where I would introduce Turbine from the start.
Any ideas on how I can start to debug this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜血缘 2024-08-22 08:00:59

我想说的是,不知何故,你将输出压缩两次。检查从 .cctor 调用 Application_Start() 后以及从 ASP.NET 引擎调用 Application_Start() 后加载的 Response.Filter 和 HttpModules。

或者,确保您安装了克林贡字体;-)

I'd say that somehow you're gzipping the output twice. Check out Response.Filter and HttpModules loaded after Application_Start() is called from your .cctor and after it's called from the ASP.NET engine.

Alternatively, make sure you have the Klingon fonts installed ;-)

扭转时空 2024-08-22 08:00:59

Turbine 不会为您的应用程序添加任何压缩,因此这是一个不同的问题。

但是,对于 Application_Start 方法,您不应在静态构造函数中调用它。

您应该做的是重写 Startup 方法并在此处执行任何逻辑。但是,这不会授予对您为应用程序配置的 IServiceLocator 的访问权限。如果您需要 IServiceLocator,请重写 PostServiceLocatorAcquisition 方法,然后可以使用 ServiceLocator 属性来访问它。

我希望这有帮助!

Turbine doesn't add any compression to your application, so that's a different issue.

However, for the Application_Start method, you should not call it within your static constructor.

What you should do instead is override the Startup method and perform any logic here. However, this will not give access to the IServiceLocator you've configured for the application. If you need the IServiceLocator, override the PostServiceLocatorAcquisition method, the can use the ServiceLocator property to have access to it.

I hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文