Configure ashx ing
Spring. netCan be easily processedProgramFor
AshxFor example, the supported ing processing class is spring. Web. Support. defaulthandlerfactory, which is also defined in the Assembly spring. Web.
You can add the ing configuration for *. ashx in the web. config configuration.
< 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 >
Then, in the configuration file, configure it directly, similar to page ing.
For example, we define such a general processing program.
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 ;
}
}
}
}
In the configuration file, you can configure and inject the following configurations.
<ObjectName= "Handler1.ashx">
<PropertyName= "Message"Value= "Hello, world ."/>
</Object>
Configure multiple ing rules
If the extension is not. ashx, for example, not directly supported by ASP. NET, you can also useSpring. Web. Support. mappinghandlerfactory.
The steps are slightly more.
First, map the extension to the processing factory in the web. config configuration file.
<AddVerb= "*"Path= "*. Ashx"Type= "Spring. Web. Support. mappinghandlerfactory, spring. Web"Validate= "True"/>
Then, define a specific ing rule, which needs to be defined by mappinghandlerfactoryconfigurer, which can also be defined in the configuration file. In its configuration, perform various specific mappings. For example, if the request extension is ashx, defaulthandlerfactory is actually used for processing. Of course, at this time, you need to define a defaulthandlerfactory object to use. The specific configuration is as follows.
<! -- Map multiple extensions -->
< Object Name = "Mappinghandlerfactoryconfigurer" Type = "Spring. Web. Support. mappinghandlerfactoryconfigurer, spring. Web" >
< Property Name = "Handlermap" >
< Dictionary >
<! -- Configure the ashx extension ing -->
< Entry Key = "\. Ashx $" Value = "Standardhandlerfactory" />
</ Dictionary >
</ Property >
</ Object >
<! -- Actual processing type -->
< Object Name = "Standardhandlerfactory" Type = "Spring. Web. Support. defaulthandlerfactory, spring. Web" />
The complete example file is as follows:
Web. config file
<? 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 >
<! -- Reference configuration file -->
< Context >
< Resource Uri = "~ /Web. xml" />
</ Context >
</ Spring >
< System. Web >
< Httpmodules >
< Add Name = "Spring" Type = "Spring. Context. Support. websuppmodule module, 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 file
<? 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 >
<! -- Map multiple extensions -->
< Object Name = "Mappinghandlerfactoryconfigurer" Type = "Spring. Web. Support. mappinghandlerfactoryconfigurer, spring. Web" >
< Property Name = "Handlermap" >
< Dictionary >
<! -- Configure the ashx extension ing -->
< Entry Key = "\. Ashx $" Value = "Standardhandlerfactory" />
</ Dictionary >
</ Property >
</ Object >
<! -- Actual processing type -->
< Object Name = "Standardhandlerfactory" Type = "Spring. Web. Support. defaulthandlerfactory, spring. Web" />
<! -- General Handler -->
< Object Name = "Handler1.ashx" >
< Property Name = "Message" Value = "Hello, world ." >
</ Property >
</ Object >
</ Objects >