回顾一般处理程序
今天帮同学解答一个问题的时候,涉及到一般处理程序(末尾的链接讲了IHttpHandler 管道处理)了,之前在大三的时候接触过,以后再也没有接触过;现在做个笔记总价一下;
在一般处理程序里,有个IsReusable,百度翻译:可重用的
IsResuable属性指示是否可以重用于其他IHttpHandler实例;
如果设置为true,能提高性能,但要注意线程之间安全性问题 ;如果设置为false,则线程是安全的
一般情况下,都会设置成false,虽然不是性能最优,但是最安全(反正就是设置为false,就是保证安全之类的;)
1 public bool IsReusable 2 { 3 get 4 { 5 return false; 6 } 7 }
当我们打开一个网页的时候,不管请求的是静态的还是动态的资源,IIS会根据ISAPI(微软和Process软件公司联合提出的Web服务器上的API标准)这一标准,将请求的文件根据文件后缀名的不同,转 交给不同的处理程序。打开IIS可以看到,大部分文件都交给了aspnet_isapi.dll进行处理,但是aspnet_isapi.dll不可能对 所有文件都进行一样方式的处理。
为了了解aspnet_isapi.dll如何进行进一步处理的,我们可以打开C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\Web.config文件。可以看到,在<httpHandler>节点中将不同的文件类型映射给不同的handler去处理;
1 <httpHandlers> 2 <add verb="*" path="*.rules" type="System.Web.HttpForbiddenHandler" validate="true"/> 3 <add verb="*" path="*.xoml" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" validate="false"/> 4 <add path="*.svc" verb="*" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" validate="false"/> 5 <add path="trace.axd" verb="*" type="System.Web.Handlers.TraceHandler" validate="True"/> 6 <add path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" validate="True"/> 7 <add path="*.axd" verb="*" type="System.Web.HttpNotFoundHandler" validate="True"/> 8 <add path="*.aspx" verb="*" type="System.Web.UI.PageHandlerFactory" validate="True"/> 9 <add path="*.ashx" verb="*" type="System.Web.UI.SimpleHandlerFactory" validate="True"/> 10 <add path="*.asmx" verb="*" type="System.Web.Services.Protocols.WebServiceHandlerFactory, System.Web.Services, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="False"/> 11 <add path="*.rem" verb="*" type="System.Runtime.Remoting.Channels.Http.HttpRemotingHandlerFactory, System.Runtime.Remoting, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" validate="False"/> 12 <add path="*.soap" verb="*" type="System.Runtime.Remoting.Channels.Http.HttpRemotingHandlerFactory, System.Runtime.Remoting, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" validate="False"/> 13 <add path="*.asax" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 14 <add path="*.ascx" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 15 <add path="*.master" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 16 <add path="*.skin" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 17 <add path="*.browser" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 18 <add path="*.sitemap" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 19 <add path="*.dll.config" verb="GET,HEAD" type="System.Web.StaticFileHandler" validate="True"/> 20 <add path="*.exe.config" verb="GET,HEAD" type="System.Web.StaticFileHandler" validate="True"/> 21 <add path="*.config" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 22 <add path="*.cs" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 23 <add path="*.csproj" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 24 <add path="*.vb" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 25 <add path="*.vbproj" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 26 <add path="*.webinfo" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 27 <add path="*.licx" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 28 <add path="*.resx" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 29 <add path="*.resources" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 30 <add path="*.mdb" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 31 <add path="*.vjsproj" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 32 <add path="*.java" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 33 <add path="*.jsl" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 34 <add path="*.ldb" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 35 <add path="*.ad" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 36 <add path="*.dd" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 37 <add path="*.ldd" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 38 <add path="*.sd" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 39 <add path="*.cd" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 40 <add path="*.adprototype" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 41 <add path="*.lddprototype" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 42 <add path="*.sdm" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 43 <add path="*.sdmDocument" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 44 <add path="*.mdf" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 45 <add path="*.ldf" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 46 <add path="*.exclude" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 47 <add path="*.refresh" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 48 <add path="*" verb="GET,HEAD,POST" type="System.Web.DefaultHttpHandler" validate="True"/> 49 <add path="*" verb="*" type="System.Web.HttpMethodNotAllowedHandler" validate="True"/> 50 </httpHandlers> 51 52 <httpModules> 53 <add name="OutputCache" type="System.Web.Caching.OutputCacheModule"/> 54 <add name="Session" type="System.Web.SessionState.SessionStateModule"/> 55 <add name="WindowsAuthentication" type="System.Web.Security.WindowsAuthenticationModule"/> 56 <add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule"/> 57 <add name="PassportAuthentication" type="System.Web.Security.PassportAuthenticationModule"/> 58 <add name="RoleManager" type="System.Web.Security.RoleManagerModule"/> 59 <add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule"/> 60 <add name="FileAuthorization" type="System.Web.Security.FileAuthorizationModule"/> 61 <add name="AnonymousIdentification" type="System.Web.Security.AnonymousIdentificationModule"/> 62 <add name="Profile" type="System.Web.Profile.ProfileModule"/> 63 <add name="ErrorHandlerModule" type="System.Web.Mobile.ErrorHandlerModule, System.Web.Mobile, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> 64 <add name="ServiceModel" type="System.ServiceModel.Activation.HttpModule, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> 65 </httpModules>
1 <?xml version="1.0" encoding="utf-8"?><!-- the root web configuration file --><configuration> 2 <!-- 3 Using a location directive with a missing path attribute 4 scopes the configuration to the entire machine. If used in 5 conjunction with allowOverride="false", it can be used to 6 prevent configuration from being altered on the machine 7 8 Administrators that want to restrict permissions granted to 9 web applications should change the default Trust level and ensure 10 that overrides are not allowed 11 --> 12 <location allowOverride="true"> 13 <system.web> 14 <securityPolicy> 15 <trustLevel name="Full" policyFile="internal"/> 16 <trustLevel name="High" policyFile="web_hightrust.config"/> 17 <trustLevel name="Medium" policyFile="web_mediumtrust.config"/> 18 <trustLevel name="Low" policyFile="web_lowtrust.config"/> 19 <trustLevel name="Minimal" policyFile="web_minimaltrust.config"/> 20 </securityPolicy> 21 <trust level="Full" originUrl=""/> 22 </system.web> 23 </location> 24 25 <system.net> 26 <defaultProxy> 27 <proxy usesystemdefault="true"/> 28 </defaultProxy> 29 </system.net> 30 31 <system.web> 32 <authorization> 33 <allow users="*"/> 34 </authorization> 35 36 <browserCaps userAgentCacheKeyLength="64"> 37 <result type="System.Web.Mobile.MobileCapabilities, System.Web.Mobile, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> 38 </browserCaps> 39 40 <clientTarget> 41 <add alias="ie5" userAgent="Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0)"/> 42 <add alias="ie4" userAgent="Mozilla/4.0 (compatible; MSIE 4.0; Windows NT 4.0)"/> 43 <add alias="uplevel" userAgent="Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.1)"/> 44 <add alias="downlevel" userAgent="Generic Downlevel"/> 45 </clientTarget> 46 47 <compilation> 48 <assemblies> 49 <add assembly="mscorlib"/> 50 <add assembly="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> 51 <add assembly="System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> 52 <add assembly="System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> 53 <add assembly="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> 54 <add assembly="System.Web.Services, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> 55 <add assembly="System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> 56 <add assembly="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> 57 <add assembly="System.EnterpriseServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> 58 <add assembly="System.Web.Mobile, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> 59 <add assembly="*"/> 60 <add assembly="System.Runtime.Serialization, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"/> 61 <add assembly="System.IdentityModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"/> 62 <add assembly="System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> 63 <add assembly="System.ServiceModel.Web, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> 64 <add assembly="System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> 65 </assemblies> 66 <buildProviders> 67 <add extension=".aspx" type="System.Web.Compilation.PageBuildProvider"/> 68 <add extension=".ascx" type="System.Web.Compilation.UserControlBuildProvider"/> 69 <add extension=".master" type="System.Web.Compilation.MasterPageBuildProvider"/> 70 <add extension=".asmx" type="System.Web.Compilation.WebServiceBuildProvider"/> 71 <add extension=".ashx" type="System.Web.Compilation.WebHandlerBuildProvider"/> 72 <add extension=".soap" type="System.Web.Compilation.WebServiceBuildProvider"/> 73 <add extension=".resx" type="System.Web.Compilation.ResXBuildProvider"/> 74 <add extension=".resources" type="System.Web.Compilation.ResourcesBuildProvider"/> 75 <add extension=".wsdl" type="System.Web.Compilation.WsdlBuildProvider"/> 76 <add extension=".xsd" type="System.Web.Compilation.XsdBuildProvider"/> 77 <add extension=".js" type="System.Web.Compilation.ForceCopyBuildProvider"/> 78 <add extension=".lic" type="System.Web.Compilation.IgnoreFileBuildProvider"/> 79 <add extension=".licx" type="System.Web.Compilation.IgnoreFileBuildProvider"/> 80 <add extension=".exclude" type="System.Web.Compilation.IgnoreFileBuildProvider"/> 81 <add extension=".refresh" type="System.Web.Compilation.IgnoreFileBuildProvider"/> 82 <add extension=".svc" type="System.ServiceModel.Activation.ServiceBuildProvider, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> 83 <add extension=".xoml" type="System.ServiceModel.Activation.WorkflowServiceBuildProvider, System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> 84 </buildProviders> 85 <expressionBuilders> 86 <add expressionPrefix="Resources" type="System.Web.Compilation.ResourceExpressionBuilder"/> 87 <add expressionPrefix="ConnectionStrings" type="System.Web.Compilation.ConnectionStringsExpressionBuilder"/> 88 <add expressionPrefix="AppSettings" type="System.Web.Compilation.AppSettingsExpressionBuilder"/> 89 </expressionBuilders> 90 </compilation> 91 92 <healthMonitoring> 93 <bufferModes> 94 <add name="Critical Notification" maxBufferSize="100" maxFlushSize="20" urgentFlushThreshold="1" regularFlushInterval="Infinite" urgentFlushInterval="00:01:00" maxBufferThreads="1"/> 95 <add name="Notification" maxBufferSize="300" maxFlushSize="20" urgentFlushThreshold="1" regularFlushInterval="Infinite" urgentFlushInterval="00:01:00" maxBufferThreads="1"/> 96 <add name="Analysis" maxBufferSize="1000" maxFlushSize="100" urgentFlushThreshold="100" regularFlushInterval="00:05:00" urgentFlushInterval="00:01:00" maxBufferThreads="1"/> 97 <add name="Logging" maxBufferSize="1000" maxFlushSize="200" urgentFlushThreshold="800" regularFlushInterval="00:30:00" urgentFlushInterval="00:05:00" maxBufferThreads="1"/> 98 </bufferModes> 99 100 <providers> 101 <add name="EventLogProvider" type="System.Web.Management.EventLogWebEventProvider,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"/> 102 <add connectionStringName="LocalSqlServer" maxEventDetailsLength="1073741823" buffer="false" bufferMode="Notification" name="SqlWebEventProvider" type="System.Web.Management.SqlWebEventProvider,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"/> 103 <add name="WmiWebEventProvider" type="System.Web.Management.WmiWebEventProvider,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"/> 104 </providers> 105 106 <profiles> 107 <add name="Default" minInstances="1" maxLimit="Infinite" minInterval="00:01:00" custom=""/> 108 <add name="Critical" minInstances="1" maxLimit="Infinite" minInterval="00:00:00" custom=""/> 109 </profiles> 110 111 <rules> 112 <add name="All Errors Default" eventName="All Errors" provider="EventLogProvider" profile="Default" minInstances="1" maxLimit="Infinite" minInterval="00:01:00" custom=""/> 113 <add name="Failure Audits Default" eventName="Failure Audits" provider="EventLogProvider" profile="Default" minInstances="1" maxLimit="Infinite" minInterval="00:01:00" custom=""/> 114 </rules> 115 116 <eventMappings> 117 <add name="All Events" type="System.Web.Management.WebBaseEvent,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" startEventCode="0" endEventCode="2147483647"/> 118 <add name="Heartbeats" type="System.Web.Management.WebHeartbeatEvent,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" startEventCode="0" endEventCode="2147483647"/> 119 <add name="Application Lifetime Events" type="System.Web.Management.WebApplicationLifetimeEvent,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" startEventCode="0" endEventCode="2147483647"/> 120 <add name="Request Processing Events" type="System.Web.Management.WebRequestEvent,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" startEventCode="0" endEventCode="2147483647"/> 121 <add name="All Errors" type="System.Web.Management.WebBaseErrorEvent,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" startEventCode="0" endEventCode="2147483647"/> 122 <add name="Infrastructure Errors" type="System.Web.Management.WebErrorEvent,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" startEventCode="0" endEventCode="2147483647"/> 123 <add name="Request Processing Errors" type="System.Web.Management.WebRequestErrorEvent,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" startEventCode="0" endEventCode="2147483647"/> 124 <add name="All Audits" type="System.Web.Management.WebAuditEvent,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" startEventCode="0" endEventCode="2147483647"/> 125 <add name="Failure Audits" type="System.Web.Management.WebFailureAuditEvent,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" startEventCode="0" endEventCode="2147483647"/> 126 <add name="Success Audits" type="System.Web.Management.WebSuccessAuditEvent,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" startEventCode="0" endEventCode="2147483647"/> 127 </eventMappings> 128 129 </healthMonitoring> 130 131 <httpHandlers> 132 <add verb="*" path="*.rules" type="System.Web.HttpForbiddenHandler" validate="true"/> 133 <add verb="*" path="*.xoml" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" validate="false"/> 134 <add path="*.svc" verb="*" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" validate="false"/> 135 <add path="trace.axd" verb="*" type="System.Web.Handlers.TraceHandler" validate="True"/> 136 <add path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" validate="True"/> 137 <add path="*.axd" verb="*" type="System.Web.HttpNotFoundHandler" validate="True"/> 138 <add path="*.aspx" verb="*" type="System.Web.UI.PageHandlerFactory" validate="True"/> 139 <add path="*.ashx" verb="*" type="System.Web.UI.SimpleHandlerFactory" validate="True"/> 140 <add path="*.asmx" verb="*" type="System.Web.Services.Protocols.WebServiceHandlerFactory, System.Web.Services, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="False"/> 141 <add path="*.rem" verb="*" type="System.Runtime.Remoting.Channels.Http.HttpRemotingHandlerFactory, System.Runtime.Remoting, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" validate="False"/> 142 <add path="*.soap" verb="*" type="System.Runtime.Remoting.Channels.Http.HttpRemotingHandlerFactory, System.Runtime.Remoting, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" validate="False"/> 143 <add path="*.asax" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 144 <add path="*.ascx" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 145 <add path="*.master" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 146 <add path="*.skin" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 147 <add path="*.browser" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 148 <add path="*.sitemap" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 149 <add path="*.dll.config" verb="GET,HEAD" type="System.Web.StaticFileHandler" validate="True"/> 150 <add path="*.exe.config" verb="GET,HEAD" type="System.Web.StaticFileHandler" validate="True"/> 151 <add path="*.config" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 152 <add path="*.cs" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 153 <add path="*.csproj" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 154 <add path="*.vb" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 155 <add path="*.vbproj" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 156 <add path="*.webinfo" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 157 <add path="*.licx" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 158 <add path="*.resx" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 159 <add path="*.resources" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 160 <add path="*.mdb" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 161 <add path="*.vjsproj" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 162 <add path="*.java" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 163 <add path="*.jsl" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 164 <add path="*.ldb" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 165 <add path="*.ad" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 166 <add path="*.dd" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 167 <add path="*.ldd" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 168 <add path="*.sd" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 169 <add path="*.cd" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 170 <add path="*.adprototype" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 171 <add path="*.lddprototype" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 172 <add path="*.sdm" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 173 <add path="*.sdmDocument" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 174 <add path="*.mdf" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 175 <add path="*.ldf" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 176 <add path="*.exclude" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 177 <add path="*.refresh" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/> 178 <add path="*" verb="GET,HEAD,POST" type="System.Web.DefaultHttpHandler" validate="True"/> 179 <add path="*" verb="*" type="System.Web.HttpMethodNotAllowedHandler" validate="True"/> 180 </httpHandlers> 181 182 <httpModules> 183 <add name="OutputCache" type="System.Web.Caching.OutputCacheModule"/> 184 <add name="Session" type="System.Web.SessionState.SessionStateModule"/> 185 <add name="WindowsAuthentication" type="System.Web.Security.WindowsAuthenticationModule"/> 186 <add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule"/> 187 <add name="PassportAuthentication" type="System.Web.Security.PassportAuthenticationModule"/> 188 <add name="RoleManager" type="System.Web.Security.RoleManagerModule"/> 189 <add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule"/> 190 <add name="FileAuthorization" type="System.Web.Security.FileAuthorizationModule"/> 191 <add name="AnonymousIdentification" type="System.Web.Security.AnonymousIdentificationModule"/> 192 <add name="Profile" type="System.Web.Profile.ProfileModule"/> 193 <add name="ErrorHandlerModule" type="System.Web.Mobile.ErrorHandlerModule, System.Web.Mobile, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> 194 <add name="ServiceModel" type="System.ServiceModel.Activation.HttpModule, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> 195 </httpModules> 196 197 <mobileControls sessionStateHistorySize="6" cookielessDataDictionaryType="System.Web.Mobile.CookielessData"> 198 <device name="XhtmlDeviceAdapters" predicateClass="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlPageAdapter" predicateMethod="DeviceQualifies" pageAdapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlPageAdapter"> 199 200 <control name="System.Web.UI.MobileControls.Panel" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlPanelAdapter"/> 201 <control name="System.Web.UI.MobileControls.Form" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlFormAdapter"/> 202 <control name="System.Web.UI.MobileControls.TextBox" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlTextBoxAdapter"/> 203 <control name="System.Web.UI.MobileControls.Label" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlLabelAdapter"/> 204 <control name="System.Web.UI.MobileControls.LiteralText" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlLiteralTextAdapter"/> 205 <control name="System.Web.UI.MobileControls.Link" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlLinkAdapter"/> 206 <control name="System.Web.UI.MobileControls.Command" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlCommandAdapter"/> 207 <control name="System.Web.UI.MobileControls.PhoneCall" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlPhoneCallAdapter"/> 208 <control name="System.Web.UI.MobileControls.List" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlListAdapter"/> 209 <control name="System.Web.UI.MobileControls.SelectionList" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlSelectionListAdapter"/> 210 <control name="System.Web.UI.MobileControls.ObjectList" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlObjectListAdapter"/> 211 <control name="System.Web.UI.MobileControls.Image" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlImageAdapter"/> 212 <control name="System.Web.UI.MobileControls.ValidationSummary" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlValidationSummaryAdapter"/> 213 <control name="System.Web.UI.MobileControls.Calendar" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlCalendarAdapter"/> 214 <control name="System.Web.UI.MobileControls.TextView" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlTextViewAdapter"/> 215 <control name="System.Web.UI.MobileControls.MobileControl" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlControlAdapter"/> 216 <control name="System.Web.UI.MobileControls.BaseValidator" adapter="System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlValidatorAdapter"/> 217 </device> 218 <device name="HtmlDeviceAdapters" predicateClass="System.Web.UI.MobileControls.Adapters.HtmlPageAdapter" predicateMethod="DeviceQualifies" pageAdapter="System.Web.UI.MobileControls.Adapters.HtmlPageAdapter"> 219 220 <control name="System.Web.UI.MobileControls.Panel" adapter="System.Web.UI.MobileControls.Adapters.HtmlPanelAdapter"/> 221 <control name="System.Web.UI.MobileControls.Form" adapter="System.Web.UI.MobileControls.Adapters.HtmlFormAdapter"/> 222 <control name="System.Web.UI.MobileControls.TextBox" adapter="System.Web.UI.MobileControls.Adapters.HtmlTextBoxAdapter"/> 223 <control name="System.Web.UI.MobileControls.Label" adapter="System.Web.UI.MobileControls.Adapters.HtmlLabelAdapter"/> 224 <control name="System.Web.UI.MobileControls.LiteralText" adapter="System.Web.UI.MobileControls.Adapters.HtmlLiteralTextAdapter"/> 225 <control name="System.Web.UI.MobileControls.Link" adapter="System.Web.UI.MobileControls.Adapters.HtmlLinkAdapter"/> 226 <control name="System.Web.UI.MobileControls.Command" adapter="System.Web.UI.MobileControls.Adapters.HtmlCommandAdapter"/> 227 <control name="System.Web.UI.MobileControls.PhoneCall" adapter="System.Web.UI.MobileControls.Adapters.HtmlPhoneCallAdapter"/> 228 <control name="System.Web.UI.MobileControls.List" adapter="System.Web.UI.MobileControls.Adapters.HtmlListAdapter"/> 229 <control name="System.Web.UI.MobileControls.SelectionList" adapter="System.Web.UI.MobileControls.Adapters.HtmlSelectionListAdapter"/> 230 <control name="System.Web.UI.MobileControls.ObjectList" adapter="System.Web.UI.MobileControls.Adapters.HtmlObjectListAdapter"/> 231 <control name="System.Web.UI.MobileControls.Image" adapter="System.Web.UI.MobileControls.Adapters.HtmlImageAdapter"/> 232 <control name="System.Web.UI.MobileControls.BaseValidator" adapter="System.Web.UI.MobileControls.Adapters.HtmlValidatorAdapter"/> 233 <control name="System.Web.UI.MobileControls.ValidationSummary" adapter="System.Web.UI.MobileControls.Adapters.HtmlValidationSummaryAdapter"/> 234 <control name="System.Web.UI.MobileControls.Calendar" adapter="System.Web.UI.MobileControls.Adapters.HtmlCalendarAdapter"/> 235 <control name="System.Web.UI.MobileControls.TextView" adapter="System.Web.UI.MobileControls.Adapters.HtmlTextViewAdapter"/> 236 <control name="System.Web.UI.MobileControls.MobileControl" adapter="System.Web.UI.MobileControls.Adapters.HtmlControlAdapter"/> 237 </device> 238 <device name="UpWmlDeviceAdapters" inheritsFrom="WmlDeviceAdapters" predicateClass="System.Web.UI.MobileControls.Adapters.UpWmlPageAdapter" predicateMethod="DeviceQualifies" pageAdapter="System.Web.UI.MobileControls.Adapters.UpWmlPageAdapter"> 239 </device> 240 <device name="WmlDeviceAdapters" predicateClass="System.Web.UI.MobileControls.Adapters.WmlPageAdapter" predicateMethod="DeviceQualifies" pageAdapter="System.Web.UI.MobileControls.Adapters.WmlPageAdapter"> 241 242 <control name="System.Web.UI.MobileControls.Panel" adapter="System.Web.UI.MobileControls.Adapters.WmlPanelAdapter"/> 243 <control name="System.Web.UI.MobileControls.Form" adapter="System.Web.UI.MobileControls.Adapters.WmlFormAdapter"/> 244 <control name="System.Web.UI.MobileControls.TextBox" adapter="System.Web.UI.MobileControls.Adapters.WmlTextBoxAdapter"/> 245 <control name="System.Web.UI.MobileControls.Label" adapter="System.Web.UI.MobileControls.Adapters.WmlLabelAdapter"/> 246 <control name="System.Web.UI.MobileControls.LiteralText" adapter="System.Web.UI.MobileControls.Adapters.WmlLiteralTextAdapter"/> 247 <control name="System.Web.UI.MobileControls.Link" adapter="System.Web.UI.MobileControls.Adapters.WmlLinkAdapter"/> 248 <control name="System.Web.UI.MobileControls.Command" adapter="System.Web.UI.MobileControls.Adapters.WmlCommandAdapter"/> 249 <control name="System.Web.UI.MobileControls.PhoneCall" adapter="System.Web.UI.MobileControls.Adapters.WmlPhoneCallAdapter"/> 250 <control name="System.Web.UI.MobileControls.List" adapter="System.Web.UI.MobileControls.Adapters.WmlListAdapter"/> 251 <control name="System.Web.UI.MobileControls.SelectionList" adapter="System.Web.UI.MobileControls.Adapters.WmlSelectionListAdapter"/> 252 <control name="System.Web.UI.MobileControls.ObjectList" adapter="System.Web.UI.MobileControls.Adapters.WmlObjectListAdapter"/> 253 <control name="System.Web.UI.MobileControls.Image" adapter="System.Web.UI.MobileControls.Adapters.WmlImageAdapter"/> 254 <control name="System.Web.UI.MobileControls.BaseValidator" adapter="System.Web.UI.MobileControls.Adapters.WmlValidatorAdapter"/> 255 <control name="System.Web.UI.MobileControls.ValidationSummary" adapter="System.Web.UI.MobileControls.Adapters.WmlValidationSummaryAdapter"/> 256 <control name="System.Web.UI.MobileControls.Calendar" adapter="System.Web.UI.MobileControls.Adapters.WmlCalendarAdapter"/> 257 <control name="System.Web.UI.MobileControls.TextView" adapter="System.Web.UI.MobileControls.Adapters.WmlTextViewAdapter"/> 258 <control name="System.Web.UI.MobileControls.MobileControl" adapter="System.Web.UI.MobileControls.Adapters.WmlControlAdapter"/> 259 </device> 260 <device name="ChtmlDeviceAdapters" inheritsFrom="HtmlDeviceAdapters" predicateClass="System.Web.UI.MobileControls.Adapters.ChtmlPageAdapter" predicateMethod="DeviceQualifies" pageAdapter="System.Web.UI.MobileControls.Adapters.ChtmlPageAdapter"> 261 262 <control name="System.Web.UI.MobileControls.Form" adapter="System.Web.UI.MobileControls.Adapters.ChtmlFormAdapter"/> 263 <control name="System.Web.UI.MobileControls.Calendar" adapter="System.Web.UI.MobileControls.Adapters.ChtmlCalendarAdapter"/> 264 <control name="System.Web.UI.MobileControls.Image" adapter="System.Web.UI.MobileControls.Adapters.ChtmlImageAdapter"/> 265 <control name="System.Web.UI.MobileControls.TextBox" adapter="System.Web.UI.MobileControls.Adapters.ChtmlTextBoxAdapter"/> 266 <control name="System.Web.UI.MobileControls.SelectionList" adapter="System.Web.UI.MobileControls.Adapters.ChtmlSelectionListAdapter"/> 267 <control name="System.Web.UI.MobileControls.Command" adapter="System.Web.UI.MobileControls.Adapters.ChtmlCommandAdapter"/> 268 <control name="System.Web.UI.MobileControls.PhoneCall" adapter="System.Web.UI.MobileControls.Adapters.ChtmlPhoneCallAdapter"/> 269 <control name="System.Web.UI.MobileControls.Link" adapter="System.Web.UI.MobileControls.Adapters.ChtmlLinkAdapter"/> 270 </device> 271 </mobileControls> 272 273 <pages> 274 <namespaces> 275 <add namespace="System"/> 276 <add namespace="System.Collections"/> 277 <add namespace="System.Collections.Specialized"/> 278 <add namespace="System.Configuration"/> 279 <add namespace="System.Text"/> 280 <add namespace="System.Text.RegularExpressions"/> 281 <add namespace="System.Web"/> 282 <add namespace="System.Web.Caching"/> 283 <add namespace="System.Web.SessionState"/> 284 <add namespace="System.Web.Security"/> 285 <add namespace="System.Web.Profile"/> 286 <add namespace="System.Web.UI"/> 287 <add namespace="System.Web.UI.WebControls"/> 288 <add namespace="System.Web.UI.WebControls.WebParts"/> 289 <add namespace="System.Web.UI.HtmlControls"/> 290 </namespaces> 291 292 <controls> 293 <add tagPrefix="asp" namespace="System.Web.UI.WebControls.WebParts" assembly="System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> 294 </controls> 295 </pages> 296 297 <protocols/> 298 299 <siteMap> 300 <providers> 301 <add siteMapFile="web.sitemap" name="AspNetXmlSiteMapProvider" type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> 302 </providers> 303 </siteMap> 304 305 <urlMappings enabled="true"/> 306 307 <webControls clientScriptsLocation="/aspnet_client/{0}/{1}/"/> 308 309 <webParts> 310 <personalization> 311 <providers> 312 <add connectionStringName="LocalSqlServer" name="AspNetSqlPersonalizationProvider" type="System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> 313 </providers> 314 315 <authorization> 316 <deny users="*" verbs="enterSharedScope"/> 317 <allow users="*" verbs="modifyState"/> 318 </authorization> 319 </personalization> 320 321 <transformers> 322 <add name="RowToFieldTransformer" type="System.Web.UI.WebControls.WebParts.RowToFieldTransformer"/> 323 <add name="RowToParametersTransformer" type="System.Web.UI.WebControls.WebParts.RowToParametersTransformer"/> 324 </transformers> 325 </webParts> 326 </system.web> 327 </configuration>
一般的html文件请求后台可以请求一般处理程序;
一般处理程序的启动函数是:
一般处理程序可以之久通过类名.ashx进行运行,例如:http://localhost:6988/Handler1.ashx
但是一开始的时候获取会出现这样的错误:没有为请求的 URL 配置默认文档,并且没有在服务器上启用目录浏览(方法一,不行的话载配置方法二;重启iis--》cmd iisresert)
1 namespace WebApplication1 2 { 3 /// <summary> 4 /// 通常是实现IHttpHandler接口,因为不必继承自Page类, 5 /// 所以没有那么多事件需要处理,不必消耗太多资源,所以性能方面要比aspx高 6 /// </summary> 7 public class Handler1 : IHttpHandler 8 { 9 10 //ProcessRequest这个方法虽然是无返回值,但是我们可以通过context.Response.Write("字符串类型")向外输入数据 11 //还有就是这个方法,就是程序的‘主函数’,程序的运行从这里开启; 12 public void ProcessRequest(HttpContext context) 13 { 14 context.Response.ContentType = "text/plain"; 15 16 context.Response.Write("Hello World"); 17 } 18 19 public bool IsReusable 20 { 21 get 22 { 23 return false; 24 } 25 } 26 } 27 }
关于ashx的返回值的问题、;先看一个问题;
text/html与text/plain有什么区别
1 IsReusable属性用来表示在IHttpHandlerFactory对象创建IHttpHandler的时候是否能够将这个Handler存入池中以便重用。 2 3 一般处理程序(HttpHandler):是一个实现System.Web.IHttpHandler接口的特殊类。任何一个实现了IHttpHandler接口的类,是作为一个外部请求的目标程序的前提。(凡是没有实现此接口的类,就不能被浏览器请求。) 4 5 它由支持ASP.NET的服务器调用和启动运行。一个HttpHandler程序负责处理它所对应的一个或一组URL地址的访问请求,并接收客户端发出的访问请求信息(请求报文)和产生响应内容(响应报文)。 6 7 简单的说:咱可以通过创建一个我们自己的HttpHandler程序来生成浏览器代码发送回客户端浏览器。 8 9 HttpHandler程序可以完成普通类程序所能完成的大多数任务: 10 11 1.获取客户端通过HTML的Form表单提交的数据和URL参数 12 13 2.创建对客户端的响应消息内容 14 15 3.访问服务器端的文件系统 16 17 4.连接数据库并开发基于数据库的应用 18 19 5.调用其他类
1 请求管道的19个事件: 2 3 (1)BeginRequest: 开始处理请求 4 5 (2)AuthenticateRequest授权验证请求,获取用户授权信息 6 7 (3):PostAuthenticateRequest获取成功 8 9 (4): AunthorizeRequest 授权,一般来检查用户是否获得权限 10 11 (5):PostAuthorizeRequest:获得授权 12 13 (6):ResolveRequestCache:获取页面缓存结果 14 15 (7):PostResolveRequestCache 已获取缓存 当前请求映射到MvcHandler(pr): 创建控制器工厂 ,创建控制器,调用action执行, 16 17 view→response 18 19 (8):PostMapRequestHandler 创建页面对象:创建 最终处理当前http请求的 Handler 实例: 第一从HttpContext中获取当前的PR Handler 20 21 ,Create 22 23 (9):PostAcquireRequestState 获取Session 24 25 (10)PostAcquireRequestState 获得Session 26 27 (11)PreRequestHandlerExecute:准备执行页面对象 28 执行页面对象的ProcessRequest方法 29 30 (12)PostRequestHandlerExecute 执行完页面对象了 31 32 (13)ReleaseRequestState 释放请求状态 33 34 (14)PostReleaseRequestState 已释放请求状态 35 36 (15)UpdateRequestCache 更新缓存 37 38 (16)PostUpdateRequestCache 已更新缓存 39 40 (17)LogRequest 日志记录 41 42 (18)PostLogRequest 已完成日志 43 44 (19)EndRequest 完成、