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

发布于 2024-10-29 08:48:19 字数 1548 浏览 2 评论 0原文

我陷入了在 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>

然后我尝试将 WebApplicationContext 添加到我的 Application 对象,以便在任何 .aspx 页面上使用;

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

我得到的例外是;

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

我花了一些时间谷歌搜索,但没有成功。我在 Spring.NET 文档中找到了; “在 Web 应用程序中 Spring 提供了 通过添加自定义 HTTP 模块和 HTTP 来配置的 WebApplicationContext 实现 处理程序到您的 Web.config 文件。请参阅有关 Web 配置的部分以获取更多详细信息。”但这根本没有发生。

请问有人可以帮助我吗?

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?

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

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

发布评论

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

评论(2

大姐,你呐 2024-11-05 08:48:19

spring.net 容器未在 Application_Start 上初始化。

顺便说一句,为什么要在 Application 存储桶中添加容器?对我来说这听起来像是一个反模式......

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

〆一缕阳光ご 2024-11-05 08:48:19

将其添加到system.webServer配置节点:

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

如果您在IIS7中使用integratedMode

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

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