RouteCollection.Ignore Method (String, Object)

Defines a URL pattern that should not be checked for matches against routes if a request URL meets the specified constraints.

Namespace:  System.Web.Routing
Assembly:  System.Web (in System.Web.dll)

public void Ignore(
	string url,
	Object constraints
)

Parameters

url
Type: System.String

The URL pattern to be ignored.

constraints
Type: System.Object

Additional criteria that determine whether a request that matches the URL pattern will be ignored.

ExceptionCondition
ArgumentNullException

The url parameter is null.

This method creates a route that is mapped to the StopRoutingHandler route handler. After you call this method, requests that match the specified URL pattern will not be processed as route requests.

ASP.NET routing automatically ignores requests when the URL matches a physical file, such as an image file. In some cases you might also want routing to ignore requests when there is no physical file. For example, the requests that ASP.NET automatically makes for .axd files should not be treated as route requests even though there is no physical file that corresponds to the .axd file-name extension.

The following example shows how to use this method to ignore all URLs that have an .aspx extension. You might want to do this if you register a custom HTTP handler to handle all URLs for files that have the extension ".aspx". A single URL pattern that would match all .aspx requests would require two catchall parameters such as {*path}.aspx/{*pathinfo}. (This pattern would match any URL that ends in .aspx, including those that have query-string parameters.) However, routing allows only one catchall parameter at the end. As an alternative, you can specify a URL pattern that has a single catchall parameter that matches all URLs and then specify constraints that exclude everything that does not have the .aspx extension, as shown in the following example:

routes.Ignore("{*allaspx}", new {allaspx=@".*\.aspx(/.*)?"});

The previous line of code would typically be added to a method that is called from the Application_Start method in the Global.asax, as shown in the example for the Ignore(String) overload.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft