Class UrlHelper
Contains methods to build URLs for ASP.NET MVC within an application.
public class UrlHelper
- Inheritance
-
UrlHelper
- Inherited Members
Constructors
UrlHelper()
Initializes a new instance of the UrlHelper class.
public UrlHelper()
UrlHelper(RequestContext)
Initializes a new instance of the UrlHelper class using the specified request context.
public UrlHelper(RequestContext requestContext)
Parameters
requestContextRequestContextAn object that contains information about the current request and about the route that it matched.
UrlHelper(RequestContext, RouteCollection)
Initializes a new instance of the UrlHelper class using the specified request context and route collection.
public UrlHelper(RequestContext requestContext, RouteCollection routeCollection)
Parameters
requestContextRequestContextAn object that contains information about the current request and about the route that it matched.
routeCollectionRouteCollectionA collection of routes.
Properties
RequestContext
Gets information about an HTTP request that matches a defined route.
public RequestContext RequestContext { get; }
Property Value
- RequestContext
The request context.
RouteCollection
Gets a collection that contains the routes that are registered for the application.
public RouteCollection RouteCollection { get; }
Property Value
- RouteCollection
The route collection.
Methods
Action()
Generates a string to a fully qualified URL to an action method.
public virtual string Action()
Returns
- string
A string to a fully qualified URL to an action method.
Action(string)
Generates a fully qualified URL to an action method by using the specified action name.
public virtual string Action(string actionName)
Parameters
actionNamestringThe name of the action method.
Returns
- string
The fully qualified URL to an action method.
Action(string, object)
Generates a fully qualified URL to an action method by using the specified action name and route values.
public virtual string Action(string actionName, object routeValues)
Parameters
actionNamestringThe name of the action method.
routeValuesobjectAn object that contains the parameters for a route. The parameters are retrieved through reflection by examining the properties of the object. The object is typically created by using object initializer syntax.
Returns
- string
The fully qualified URL to an action method.
Action(string, string)
Generates a fully qualified URL to an action method by using the specified action name and controller name.
public virtual string Action(string actionName, string controllerName)
Parameters
Returns
- string
The fully qualified URL to an action method.
Action(string, string, object)
Generates a fully qualified URL to an action method by using the specified action name, controller name, and route values.
public virtual string Action(string actionName, string controllerName, object routeValues)
Parameters
actionNamestringThe name of the action method.
controllerNamestringThe name of the controller.
routeValuesobjectAn object that contains the parameters for a route. The parameters are retrieved through reflection by examining the properties of the object. The object is typically created by using object initializer syntax.
Returns
- string
The fully qualified URL to an action method.
Action(string, string, object, string)
Generates a fully qualified URL to an action method by using the specified action name, controller name, route values, and protocol to use.
public virtual string Action(string actionName, string controllerName, object routeValues, string protocol)
Parameters
actionNamestringThe name of the action method.
controllerNamestringThe name of the controller.
routeValuesobjectAn object that contains the parameters for a route. The parameters are retrieved through reflection by examining the properties of the object. The object is typically created by using object initializer syntax.
protocolstringThe protocol for the URL, such as "http" or "https".
Returns
- string
The fully qualified URL to an action method.
Action(string, string, RouteValueDictionary)
Generates a fully qualified URL to an action method by using the specified action name, controller name, and route values.
public virtual string Action(string actionName, string controllerName, RouteValueDictionary routeValues)
Parameters
actionNamestringThe name of the action method.
controllerNamestringThe name of the controller.
routeValuesRouteValueDictionaryAn object that contains the parameters for a route.
Returns
- string
The fully qualified URL to an action method.
Action(string, string, RouteValueDictionary, string)
Generates a fully qualified URL for an action method by using the specified action name, controller name, route values, and protocol to use.
public virtual string Action(string actionName, string controllerName, RouteValueDictionary routeValues, string protocol)
Parameters
actionNamestringThe name of the action method.
controllerNamestringThe name of the controller.
routeValuesRouteValueDictionaryAn object that contains the parameters for a route.
protocolstringThe protocol for the URL, such as "http" or "https".
Returns
- string
The fully qualified URL to an action method.
Action(string, string, RouteValueDictionary, string, string)
Generates a fully qualified URL for an action method by using the specified action name, controller name, route values, protocol to use and host name.
public virtual string Action(string actionName, string controllerName, RouteValueDictionary routeValues, string protocol, string hostName)
Parameters
actionNamestringThe name of the action method.
controllerNamestringThe name of the controller.
routeValuesRouteValueDictionaryAn object that contains the parameters for a route.
protocolstringThe protocol for the URL, such as "http" or "https".
hostNamestringThe host name for the URL.
Returns
- string
The fully qualified URL to an action method.
Action(string, RouteValueDictionary)
Generates a fully qualified URL to an action method for the specified action name and route values.
public virtual string Action(string actionName, RouteValueDictionary routeValues)
Parameters
actionNamestringThe name of the action method.
routeValuesRouteValueDictionaryAn object that contains the parameters for a route.
Returns
- string
The fully qualified URL to an action method.
Content(string)
Converts a virtual (relative) path to an application absolute path.
public virtual string Content(string contentPath)
Parameters
contentPathstringThe virtual path of the content.
Returns
- string
The application absolute path.
Encode(string)
Encodes special characters in a URL string into character-entity equivalents.
public virtual string Encode(string url)
Parameters
urlstringThe text to encode.
Returns
- string
An encoded URL string.
GenerateContentUrl(string, HttpContextBase)
Returns a string that contains a content URL.
public static string GenerateContentUrl(string contentPath, HttpContextBase httpContext)
Parameters
contentPathstringThe content path.
httpContextHttpContextBaseThe http context.
Returns
- string
A string that contains a content URL.
GenerateUrl(string, string, string, string, string, string, RouteValueDictionary, RouteCollection, RequestContext, bool)
Returns a string that contains a URL.
public static string GenerateUrl(string routeName, string actionName, string controllerName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, RouteCollection routeCollection, RequestContext requestContext, bool includeImplicitMvcValues)
Parameters
routeNamestringThe route name.
actionNamestringThe action name.
controllerNamestringThe controller name.
protocolstringThe HTTP protocol.
hostNamestringThe host name.
fragmentstringThe fragment.
routeValuesRouteValueDictionaryThe route values.
routeCollectionRouteCollectionThe route collection.
requestContextRequestContextThe request context.
includeImplicitMvcValuesbooltrue to include implicit MVC values; otherwise false.
Returns
- string
A string that contains a URL.
GenerateUrl(string, string, string, RouteValueDictionary, RouteCollection, RequestContext, bool)
Returns a string that contains a URL.
public static string GenerateUrl(string routeName, string actionName, string controllerName, RouteValueDictionary routeValues, RouteCollection routeCollection, RequestContext requestContext, bool includeImplicitMvcValues)
Parameters
routeNamestringThe route name.
actionNamestringThe action name.
controllerNamestringThe controller name.
routeValuesRouteValueDictionaryThe route values.
routeCollectionRouteCollectionThe route collection.
requestContextRequestContextThe request context.
includeImplicitMvcValuesbooltrue to include implicit MVC values; otherwise false.
Returns
- string
A string that contains a URL.
HttpRouteUrl(string, object)
Generates a fully qualified URL for the specified route values.
public virtual string HttpRouteUrl(string routeName, object routeValues)
Parameters
Returns
- string
A fully qualified URL for the specified route values.
HttpRouteUrl(string, RouteValueDictionary)
Generates a fully qualified URL for the specified route values.
public virtual string HttpRouteUrl(string routeName, RouteValueDictionary routeValues)
Parameters
routeNamestringThe route name.
routeValuesRouteValueDictionaryThe route values.
Returns
- string
A fully qualified URL for the specified route values.
IsLocalUrl(string)
Returns a value that indicates whether the URL is local.
public virtual bool IsLocalUrl(string url)
Parameters
urlstringThe URL.
Returns
- bool
true if the URL is local; otherwise, false.
RouteUrl(object)
Generates a fully qualified URL for the specified route values.
public virtual string RouteUrl(object routeValues)
Parameters
routeValuesobjectAn object that contains the parameters for a route. The parameters are retrieved through reflection by examining the properties of the object. The object is typically created by using object initializer syntax.
Returns
- string
The fully qualified URL.
RouteUrl(string)
Generates a fully qualified URL for the specified route name.
public virtual string RouteUrl(string routeName)
Parameters
routeNamestringThe name of the route that is used to generate URL.
Returns
- string
The fully qualified URL.
RouteUrl(string, object)
Generates a fully qualified URL for the specified route values by using a route name.
public virtual string RouteUrl(string routeName, object routeValues)
Parameters
routeNamestringThe name of the route that is used to generate URL.
routeValuesobjectAn object that contains the parameters for a route. The parameters are retrieved through reflection by examining the properties of the object. The object is typically created by using object initializer syntax.
Returns
- string
The fully qualified URL.
RouteUrl(string, object, string)
Generates a fully qualified URL for the specified route values by using a route name and the protocol to use.
public virtual string RouteUrl(string routeName, object routeValues, string protocol)
Parameters
routeNamestringThe name of the route that is used to generate the URL.
routeValuesobjectAn object that contains the parameters for a route. The parameters are retrieved through reflection by examining the properties of the object. The object is typically created by using object initializer syntax.
protocolstringThe protocol for the URL, such as "http" or "https".
Returns
- string
The fully qualified URL.
RouteUrl(string, RouteValueDictionary)
Generates a fully qualified URL for the specified route values by using a route name.
public virtual string RouteUrl(string routeName, RouteValueDictionary routeValues)
Parameters
routeNamestringThe name of the route that is used to generate URL.
routeValuesRouteValueDictionaryAn object that contains the parameters for a route.
Returns
- string
The fully qualified URL.
RouteUrl(string, RouteValueDictionary, string, string)
Generates a fully qualified URL for the specified route values by using the specified route name, protocol to use, and host name.
public virtual string RouteUrl(string routeName, RouteValueDictionary routeValues, string protocol, string hostName)
Parameters
routeNamestringThe name of the route that is used to generate URL.
routeValuesRouteValueDictionaryAn object that contains the parameters for a route.
protocolstringThe protocol for the URL, such as "http" or "https".
hostNamestringThe host name for the URL.
Returns
- string
The fully qualified URL.
RouteUrl(RouteValueDictionary)
Generates a fully qualified URL for the specified route values.
public virtual string RouteUrl(RouteValueDictionary routeValues)
Parameters
routeValuesRouteValueDictionaryAn object that contains the parameters for a route.
Returns
- string
The fully qualified URL.