Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / Routing / UrlRoutingModule.cs / 1305376 / UrlRoutingModule.cs
namespace System.Web.Routing { using System.Diagnostics; using System.Globalization; using System.Runtime.CompilerServices; using System.Web.Security; [TypeForwardedFrom("System.Web.Routing, Version=3.5.0.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35")] public class UrlRoutingModule : IHttpModule { private static readonly object _contextKey = new Object(); private static readonly object _requestDataKey = new Object(); private RouteCollection _routeCollection; [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "This needs to be settable for unit tests.")] public RouteCollection RouteCollection { get { if (_routeCollection == null) { _routeCollection = RouteTable.Routes; } return _routeCollection; } set { _routeCollection = value; } } protected virtual void Dispose() { } protected virtual void Init(HttpApplication application) { ////////////////////////////////////////////////////////////////// // Check if this module has been already addded if (application.Context.Items[_contextKey] != null) { return; // already added to the pipeline } application.Context.Items[_contextKey] = _contextKey; // Ideally we would use the MapRequestHandler event. However, MapRequestHandler is not available // in II6 or IIS7 ISAPI Mode. Instead, we use PostResolveRequestCache, which is the event immediately // before MapRequestHandler. This allows use to use one common codepath for all versions of IIS. application.PostResolveRequestCache += OnApplicationPostResolveRequestCache; } private void OnApplicationPostResolveRequestCache(object sender, EventArgs e) { HttpContextBase context = new HttpContextWrapper(((HttpApplication)sender).Context); PostResolveRequestCache(context); } [Obsolete("This method is obsolete. Override the Init method to use the PostMapRequestHandler event.")] public virtual void PostMapRequestHandler(HttpContextBase context) { // Backwards compat with 3.5 which used to have code here to Rewrite the URL } public virtual void PostResolveRequestCache(HttpContextBase context) { // Match the incoming URL against the route table RouteData routeData = RouteCollection.GetRouteData(context); // Do nothing if no route found if (routeData == null) { return; } // If a route was found, get an IHttpHandler from the route's RouteHandler IRouteHandler routeHandler = routeData.RouteHandler; if (routeHandler == null) { throw new InvalidOperationException( String.Format( CultureInfo.CurrentUICulture, SR.GetString(SR.UrlRoutingModule_NoRouteHandler))); } // This is a special IRouteHandler that tells the routing module to stop processing // routes and to let the fallback handler handle the request. if (routeHandler is StopRoutingHandler) { return; } RequestContext requestContext = new RequestContext(context, routeData); // Dev10 766875 Adding RouteData to HttpContext context.Request.RequestContext = requestContext; IHttpHandler httpHandler = routeHandler.GetHttpHandler(requestContext); if (httpHandler == null) { throw new InvalidOperationException( String.Format( CultureInfo.CurrentUICulture, SR.GetString(SR.UrlRoutingModule_NoHttpHandler), routeHandler.GetType())); } if (httpHandler is UrlAuthFailureHandler) { if (FormsAuthenticationModule.FormsAuthRequired) { UrlAuthorizationModule.ReportUrlAuthorizationFailure(HttpContext.Current, this); return; } else { throw new HttpException(401, SR.GetString(SR.Assess_Denied_Description3)); } } // Remap IIS7 to our handler context.RemapHandler(httpHandler); } #region IHttpModule Members void IHttpModule.Dispose() { Dispose(); } void IHttpModule.Init(HttpApplication application) { Init(application); } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. namespace System.Web.Routing { using System.Diagnostics; using System.Globalization; using System.Runtime.CompilerServices; using System.Web.Security; [TypeForwardedFrom("System.Web.Routing, Version=3.5.0.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35")] public class UrlRoutingModule : IHttpModule { private static readonly object _contextKey = new Object(); private static readonly object _requestDataKey = new Object(); private RouteCollection _routeCollection; [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "This needs to be settable for unit tests.")] public RouteCollection RouteCollection { get { if (_routeCollection == null) { _routeCollection = RouteTable.Routes; } return _routeCollection; } set { _routeCollection = value; } } protected virtual void Dispose() { } protected virtual void Init(HttpApplication application) { ////////////////////////////////////////////////////////////////// // Check if this module has been already addded if (application.Context.Items[_contextKey] != null) { return; // already added to the pipeline } application.Context.Items[_contextKey] = _contextKey; // Ideally we would use the MapRequestHandler event. However, MapRequestHandler is not available // in II6 or IIS7 ISAPI Mode. Instead, we use PostResolveRequestCache, which is the event immediately // before MapRequestHandler. This allows use to use one common codepath for all versions of IIS. application.PostResolveRequestCache += OnApplicationPostResolveRequestCache; } private void OnApplicationPostResolveRequestCache(object sender, EventArgs e) { HttpContextBase context = new HttpContextWrapper(((HttpApplication)sender).Context); PostResolveRequestCache(context); } [Obsolete("This method is obsolete. Override the Init method to use the PostMapRequestHandler event.")] public virtual void PostMapRequestHandler(HttpContextBase context) { // Backwards compat with 3.5 which used to have code here to Rewrite the URL } public virtual void PostResolveRequestCache(HttpContextBase context) { // Match the incoming URL against the route table RouteData routeData = RouteCollection.GetRouteData(context); // Do nothing if no route found if (routeData == null) { return; } // If a route was found, get an IHttpHandler from the route's RouteHandler IRouteHandler routeHandler = routeData.RouteHandler; if (routeHandler == null) { throw new InvalidOperationException( String.Format( CultureInfo.CurrentUICulture, SR.GetString(SR.UrlRoutingModule_NoRouteHandler))); } // This is a special IRouteHandler that tells the routing module to stop processing // routes and to let the fallback handler handle the request. if (routeHandler is StopRoutingHandler) { return; } RequestContext requestContext = new RequestContext(context, routeData); // Dev10 766875 Adding RouteData to HttpContext context.Request.RequestContext = requestContext; IHttpHandler httpHandler = routeHandler.GetHttpHandler(requestContext); if (httpHandler == null) { throw new InvalidOperationException( String.Format( CultureInfo.CurrentUICulture, SR.GetString(SR.UrlRoutingModule_NoHttpHandler), routeHandler.GetType())); } if (httpHandler is UrlAuthFailureHandler) { if (FormsAuthenticationModule.FormsAuthRequired) { UrlAuthorizationModule.ReportUrlAuthorizationFailure(HttpContext.Current, this); return; } else { throw new HttpException(401, SR.GetString(SR.Assess_Denied_Description3)); } } // Remap IIS7 to our handler context.RemapHandler(httpHandler); } #region IHttpModule Members void IHttpModule.Dispose() { Dispose(); } void IHttpModule.Init(HttpApplication application) { Init(application); } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SelectorItemAutomationPeer.cs
- MarkupObject.cs
- XmlEventCache.cs
- NameTable.cs
- AvtEvent.cs
- UnionCqlBlock.cs
- MatrixAnimationBase.cs
- AsymmetricSignatureFormatter.cs
- EdmItemCollection.cs
- OperationContractGenerationContext.cs
- WebPartConnectionsConfigureVerb.cs
- PropertyTabAttribute.cs
- SemaphoreSecurity.cs
- IDReferencePropertyAttribute.cs
- ExpressionContext.cs
- RtfFormatStack.cs
- columnmapkeybuilder.cs
- DomainUpDown.cs
- VScrollBar.cs
- TTSEngineProxy.cs
- ToolStripDropDownItem.cs
- MarshalDirectiveException.cs
- TextTreeTextBlock.cs
- ValueExpressions.cs
- baseshape.cs
- WebDisplayNameAttribute.cs
- DataObjectCopyingEventArgs.cs
- IssuerInformation.cs
- TextRangeAdaptor.cs
- Cloud.cs
- CodeChecksumPragma.cs
- SqlBulkCopyColumnMapping.cs
- BasePropertyDescriptor.cs
- Int32Collection.cs
- TemplatePartAttribute.cs
- AmbientValueAttribute.cs
- WebServiceHostFactory.cs
- Char.cs
- AttachedPropertyBrowsableForChildrenAttribute.cs
- DataControlLinkButton.cs
- WindowsListViewItemCheckBox.cs
- FontClient.cs
- MsmqChannelFactoryBase.cs
- SqlWriter.cs
- OleDbDataReader.cs
- SmiRequestExecutor.cs
- BamlTreeMap.cs
- ReadOnlyCollectionBase.cs
- WebPartManager.cs
- AsyncPostBackTrigger.cs
- NamedPipeChannelListener.cs
- ExceptionUtil.cs
- MenuCommandsChangedEventArgs.cs
- BufferedGraphics.cs
- SspiWrapper.cs
- XmlNodeReader.cs
- ReadOnlyHierarchicalDataSource.cs
- ColorConvertedBitmap.cs
- NavigatorInput.cs
- Rotation3D.cs
- SqlUdtInfo.cs
- FamilyCollection.cs
- BoundColumn.cs
- Marshal.cs
- ProfileManager.cs
- ScriptServiceAttribute.cs
- Material.cs
- SerializableAttribute.cs
- BulletDecorator.cs
- PrefixHandle.cs
- StyleConverter.cs
- SkipQueryOptionExpression.cs
- TextHidden.cs
- Int16Animation.cs
- DynamicDiscoveryDocument.cs
- DesigntimeLicenseContext.cs
- XamlToRtfWriter.cs
- DES.cs
- XamlClipboardData.cs
- RequestDescription.cs
- QueryOperationResponseOfT.cs
- ListSurrogate.cs
- LookupBindingPropertiesAttribute.cs
- UnmanagedMemoryStream.cs
- DigitalSignature.cs
- ReadOnlyHierarchicalDataSource.cs
- validation.cs
- ScaleTransform.cs
- ObjectAnimationUsingKeyFrames.cs
- CodeNamespace.cs
- TrustLevel.cs
- NetMsmqSecurityMode.cs
- RemotingHelper.cs
- MemberProjectionIndex.cs
- FileRegion.cs
- TextServicesProperty.cs
- PerfCounters.cs
- ThrowHelper.cs
- Compress.cs
- MarkupExtensionParser.cs