Export (0) Print
Expand All

RouteCollection.Ignore Method (String)

Defines a URL pattern that should not be checked for matches against routes.

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

public void Ignore(
	string url
)

Parameters

url
Type: System.String

The URL pattern to be ignored.

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 default template for MVC projects uses this method to exclude .axd files from routing, as shown in the following example:

public class MvcApplication : System.Web.HttpApplication
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default",                                              // Route name 
            "{controller}/{action}/{id}",                           // URL with parameters 
            new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
        );

    }

    protected void Application_Start()
    {
        RegisterRoutes(RouteTable.Routes);
    }
}

.NET Framework

Supported in: 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.

Show:
© 2014 Microsoft