简体   繁体   English

无法从ContextRegistry.GetContext()获取WebApplicationContext对象:未定义“ Web”协议的资源处理程序

[英]Can't get WebApplicationContext object from ContextRegistry.GetContext(): Resource handler for the 'web' protocol is not defined

I'm stucked in configuring my web.config file under a web forms project in order to get an instance of WebApplicationContext (at Global.asax) and then being able to use scope="application | session | request" 我被困在一个Web窗体项目下配置我的web.config文件,以便获取WebApplicationContext实例(位于Global.asax),然后能够使用scope =“ application | session | request”

<sectionGroup name="spring">
    <section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/>
    <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>

<spring>
    <context type="Spring.Context.Support.WebApplicationContext, Spring.Web">
        <resource uri="~/Configuration/Spring.xml" />
    </context>
</spring>

<httpHandlers>
    <add verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web"/>
</httpHandlers>

<httpModules>
    <add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
</httpModules>

I'm then trying to add the WebApplicationContext to my Application object, in order to cosume on any .aspx page; 然后,我试图将WebApplicationContext添加到我的Application对象中,以便在任何.aspx页上使用;

protected void Application_Start(object sender, EventArgs e)
{
    //Exception happens on next line!
    Application.Add("ContainerID", ContextRegistry.GetContext());
}

Exception I'm getting is; 我得到的例外是;

"Error creating context 'spring.root': Resource handler for the 'web' protocol is not defined. Spring.NET"

I have have spent some time googling, but no success. 我花了一些时间进行谷歌搜索,但没有成功。 Ive found at Spring.NET documentation; Ive在Spring.NET文档中找到; "In web applications Spring provides a WebApplicationContext implementation which is configured by adding a custom HTTP module and HTTP handler to your Web.config file. See the section on Web Configuration for more details." “在Web应用程序中,Spring提供了一个WebApplicationContext实现,该实现是通过在Web.config文件中添加自定义HTTP模块和HTTP处理程序来配置的。有关更多详细信息,请参见Web配置部分。” But it is in no way happening. 但这绝不会发生。

Please, could someone help me? 拜托,有人可以帮我吗?

the spring.net container is not initialized on Application_Start . spring.net容器未在Application_Start初始化。

and btw, why would you want to add the container in the Application bucker? 顺便说一句,为什么要在Application bucker中添加容器? It sounds like an antipattern to me... 这听起来像是我的反模式...

Add this to system.webServer config node: 将此添加到system.webServer配置节点:

<modules runAllManagedModulesForAllRequests="true">
  <add name="Spring" preCondition="integratedMode" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
</modules>   

If you use integratedMode in IIS7 如果您在IIS7中使用IntegratedMode

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM