【问题标题】:Datatype RouteData In ASP.net MVCASP.net MVC 中的数据类型 RouteData
【发布时间】:2023-04-01 22:04:01
【问题描述】:

什么是RouteData数据类型和RouteTable:

public static RouteData GetRouteDataByUrl(string url) { return RouteTable.Routes.GetRouteData(new RewritedHttpContextBase(url)); }

【问题讨论】:

  • 您能详细说明您的问题吗?不清楚你在问什么。

标签: asp.net asp.net-mvc


【解决方案1】:

这是两个类的公共方法和属性的元数据。首先是RouteData类:

public class RouteData
{
    // Summary:
    //     Initializes a new instance of the System.Web.Routing.RouteData class.
    public RouteData();

    //
    // Summary:
    //     Initializes a new instance of the System.Web.Routing.RouteData class by using
    //     the specified route and route handler.
    //
    // Parameters:
    //   route:
    //     An object that defines the route.
    //
    //   routeHandler:
    //     An object that processes the request.
    public RouteData(RouteBase route, IRouteHandler routeHandler);

    // Summary:
    //     Gets a collection of custom values that are passed to the route handler but
    //     are not used when ASP.NET routing determines whether the route matches a
    //     request.
    //
    // Returns:
    //     An object that contains custom values.
    public RouteValueDictionary DataTokens { get; }

    //
    // Summary:
    //     Gets or sets the object that represents a route.
    //
    // Returns:
    //     An object that represents the route definition.
    public RouteBase Route { get; set; }

    //
    // Summary:
    //     Gets or sets the object that processes a requested route.
    //
    // Returns:
    //     An object that processes the route request.
    public IRouteHandler RouteHandler { get; set; }

    //
    // Summary:
    //     Gets a collection of URL parameter values and default values for the route.
    //
    // Returns:
    //     An object that contains values that are parsed from the URL and from default
    //     values.
    public RouteValueDictionary Values { get; }

    // Summary:
    //     Retrieves the value with the specified identifier.
    //
    // Parameters:
    //   valueName:
    //     The key of the value to retrieve.
    //
    // Returns:
    //     The element in the System.Web.Routing.RouteData.Values property whose key
    //     matches valueName.
    //
    // Exceptions:
    //   System.InvalidOperationException:
    //     A value does not exist for valueName.
    public string GetRequiredString(string valueName);
}

其次是RoutTable类:

// Summary:
//     Stores the URL routes for an application.
[TypeForwardedFrom("System.Web.Routing, Version=3.5.0.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35")]
public class RouteTable
{
    // Summary:
    //     Initializes a new instance of the System.Web.Routing.RouteTable class.
    [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
    public RouteTable();

    // Summary:
    //     Gets a collection of objects that derive from the System.Web.Routing.RouteBase
    //     class.
    //
    // Returns:
    //     An object that contains all the routes in the collection.
    public static RouteCollection Routes { get; }
}

您对这些课程有更具体的问题吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-09
    • 1970-01-01
    • 2020-12-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多