Szerkesztés

Megosztás a következőn keresztül:


RouteCollection.Ignore Method

Definition

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

Overloads

Ignore(String, Object)

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

Ignore(String)

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

Remarks

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.

Ignore(String, Object)

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

public:
 void Ignore(System::String ^ url, System::Object ^ constraints);
public void Ignore (string url, object constraints);
member this.Ignore : string * obj -> unit
Public Sub Ignore (url As String, constraints As Object)

Parameters

url
String

The URL pattern to be ignored.

constraints
Object

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

Exceptions

The url parameter is null.

Examples

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 With {.allaspx = ".*\.aspx(/.*)?"})
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.

Remarks

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.

See also

Applies to

Ignore(String)

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

public:
 void Ignore(System::String ^ url);
public void Ignore (string url);
member this.Ignore : string -> unit
Public Sub Ignore (url As String)

Parameters

url
String

The URL pattern to be ignored.

Examples

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);
    }
}
Public Class MvcApplication
    Inherits System.Web.HttpApplication

    Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}")

        ' MapRoute takes the following parameters, in order:
        ' (1) Route name
        ' (2) URL with parameters
        ' (3) Parameter defaults
        routes.MapRoute( _
            "Default", _
            "{controller}/{action}/{id}", _
            New With {.controller = "Home", .action = "Index", .id = ""} _
        )

    End Sub

    Sub Application_Start()
        RegisterRoutes(RouteTable.Routes)
    End Sub
End Class

Remarks

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.

See also

Applies to