简体   繁体   中英

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"

<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;

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; "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." But it is in no way happening.

Please, could someone help me?

the spring.net container is not initialized on Application_Start .

and btw, why would you want to add the container in the Application bucker? It sounds like an antipattern to me...

Add this to system.webServer config node:

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

If you use integratedMode in IIS7

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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