Spring.NETでは、asxのマッピング、その他各種マッピングの処理を設定します.

18862 ワード

アシックスマップの設定
Spring.NETでは様々な処理プログラムのマッピングが容易に行えますが、asxではサポートされているマッピング処理クラスは、Spring.Web.Support.Default Handler Factoryであり、プログラムセットSpring.Webでも定義されています.
web.com figの構成において、*.asxに対するマッピング構成を追加することができる.
<httpHandlers>
<add verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web"/>

<add verb="*" path="*.ashx" type="Spring.Web.Support.DefaultHandlerFactory, Spring.Web" validate="true"/>

<add verb="*" path="*.asmx" type="Spring.Web.Services.WebServiceHandlerFactory, Spring.Web"/>
<add verb="*" path="ContextMonitor.ashx" type="Spring.Web.Support.ContextMonitor, Spring.Web"/>
</httpHandlers>
その後、設定ファイルでは、ページマップのように直接設定すればいいです.
例えば、このような一般的な処理プログラムを定義した.
namespace Web
{
public class Handler1 : IHttpHandler
{
public string Message { get; set; }
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write( this.Message );
}

public bool IsReusable
{
get
{
return false;
}
}
}
}
設定ファイルでは、以下のように構成して注入することができる.
  <object name="Handler1.ashx">
<property name="Message" value="Hello, world."/>
</object>
複数のマッピングルールを設定
拡張子が.asxではなくて、たとえばASP.NETの直接的なサポートの拡張子ではなく、Spring.Web.Support.MappingHandler Factoryを使用することもできます.
ステップが少し多くなりました.
まず、web.co nfigプロファイルでは、拡張子をこの処理手順工場にマッピングする.
<add verb="*" path="*.ashx" type="Spring.Web.Support.MappingHandlerFactory, Spring.Web" validate="true"/>
そして、具体的なマッピングルールを定義するには、MappingHandler FactoryConfigrerによって定義する必要があり、同様に構成ファイルに定義することができる.その構成では、拡張子がasxという要求、実際にDefault Handler Factoryを使って処理するなど、様々な具体的なマッピングが行われる.もちろん、この時はDefault Handler Factoryの対象を定義して使う必要があります.具体的な配置は以下の通りです.
  <!--          -->
<object name="mappingHandlerFactoryConfigurer" type="Spring.Web.Support.MappingHandlerFactoryConfigurer, Spring.Web">
<property name="HandlerMap">
<dictionary>
<!-- ashx -->
<entry key="\.ashx$" value="standardHandlerFactory" />
</dictionary>
</property>
</object>

<!-- -->
<object name="standardHandlerFactory" type="Spring.Web.Support.DefaultHandlerFactory, Spring.Web" />
完全なサンプルファイルは以下の通りです.
web.co nfigファイル
<?xml version="1.0" encoding="utf-8"?>

<configuration>
<configSections>

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

<spring>
<!-- -->
<context>
<resource uri="~/Web.xml"/>
</context>
</spring>

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

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

<!--<add verb="*" path="*.ashx" type="Spring.Web.Support.DefaultHandlerFactory, Spring.Web" validate="true"/>-->
<add verb="*" path="*.ashx" type="Spring.Web.Support.MappingHandlerFactory, Spring.Web" validate="true"/>

<add verb="*" path="*.asmx" type="Spring.Web.Services.WebServiceHandlerFactory, Spring.Web"/>
<add verb="*" path="ContextMonitor.ashx" type="Spring.Web.Support.ContextMonitor, Spring.Web"/>
</httpHandlers>

<compilation debug="true" targetFramework="4.0" />
</system.web>

</configuration>
web.xmlファイル
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">

<!-- Referenced by main application context configuration file -->

<description>
The Northwind web layer definitions
</description>

<!-- -->
<object name="mappingHandlerFactoryConfigurer" type="Spring.Web.Support.MappingHandlerFactoryConfigurer, Spring.Web">
<property name="HandlerMap">
<dictionary>
<!-- ashx -->
<entry key="\.ashx$" value="standardHandlerFactory" />
</dictionary>
</property>
</object>

<!-- -->
<object name="standardHandlerFactory" type="Spring.Web.Support.DefaultHandlerFactory, Spring.Web" />

<!-- -->
<object name="Handler1.ashx">
<property name="Message" value="Hello, world.">
</property>
</object>

</objects>