本文介绍了HTTP模块在ASP.NET MVC不会被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个session-per-request模式在ASP.NET MVC 2 preVIEW 1的应用程序,我已经实现了一个IHttpModule的帮助我做到这一点:

I am trying to implement a session-per-request pattern in an ASP.NET MVC 2 Preview 1 application, and I've implemented an IHttpModule to help me do this:

public class SessionModule : IHttpModule
{
    public void Init(HttpApplication context)
    {
        context.Response.Write("Init!");
        context.EndRequest += context_EndRequest;
    }
    // ... etc...
}

和我已经把这个到web.config中:

And I've put this into the web.config:

  <system.web>
    <httpModules>
      <add name="SessionModule" type="MyNamespace.SessionModule" />
    </httpModules>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="SessionModule" />
      <add name="SessionModule" type="MyNamespace.SessionModule" />
    </modules>

不过,初始化!永远不会被写入页面(我使用的是内置的VS web服务器,卡西尼)。此外,我试图把断点在SessionModule但他们从来没有打破。我在想什么?

However, "Init!" never gets written to the page (I'm using the built-in VS web server, Cassini). Additionally, I've tried putting breakpoints in the SessionModule but they never break. What am I missing?

推荐答案

原来有一个在浏览文件夹中的Web.config文件,一个根。猜猜哪一个我在注册的HttpModules?是的,在浏览文件夹之一。我把它移到了根Web.config,现在,它就像一个魅力。

Turns out there's a Web.config file in the Views folder, and one in the root. Guess which one I registered the httpModules in? Yep, the Views folder one. I moved it to the root Web.config and now it works like a charm.

这篇关于HTTP模块在ASP.NET MVC不会被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 09:09