C# Class Castle.MonoRail.Framework.Services.DefaultUrlBuilder

Default implementation of IUrlBuilder
The property UseExtensions defines whether the builder should output file extension. This might be handy to use in combination with a url rewrite strategy

If you want to create a custom urlbuilder, you can extend this one and override the InternalBuildUrl(string,string,string,string,string,string,string,string,string,bool,bool,string)

Inheritance: IUrlBuilder, IServiceEnabledComponent
Show file Open project: nats/castle-1.0.3-mono Class Usage Examples

Public Methods

Method Description
BuildUrl ( System.UrlInfo current, IDictionary parameters ) : string

Builds the URL using the current url as contextual information and a parameter dictionary.

Common parameters includes area, controller and action, which outputs /area/controller/name.extension

Please note that if you dont specify an area or controller name, they will be inferred from the context. If you want to use an empty area, you must specify area=''. This is commonly a source of confusion, so understand the following cases:

UrlInfo current = ... // Assume that the current is area Admin, controller Products and action List BuildUrl(current, {action: 'view'}) // returns /Admin/Products/view.castle BuildUrl(current, {controller: 'Home', action: 'index'}) // returns /Admin/Home/index.castle BuildUrl(current, {area:'', controller: 'Home', action: 'index'}) // returns /Home/index.castle

The querystring parameter can be a string or a dictionary. It appends a query string to the url: /area/controller/name.extension?id=1

The absolute parameter forces the builder to output a full url like http://hostname/virtualdir/area/controller/name.extension

The encode parameter forces the builder to encode the querystring /controller/name.extension?id=1&name=John which is required to output full xhtml compliant content.

BuildUrl ( System.UrlInfo current, string controller, string action ) : string

Builds an URL using the controller name and action name.

BuildUrl ( System.UrlInfo current, string controller, string action, IDictionary queryStringParams ) : string

Builds an URL using the controller name, action name, and a querystring dictionary.

BuildUrl ( System.UrlInfo current, string controller, string action, NameValueCollection queryStringParams ) : string

Builds an URL using the controller name, action name, and a querystring name value collection.

BuildUrl ( System.UrlInfo current, string area, string controller, string action ) : string

Builds an URL using the area name, controller name and action name.

BuildUrl ( System.UrlInfo current, string area, string controller, string action, IDictionary queryStringParams ) : string

Builds an URL using the area name, controller name, action name, and a querystring dictionary.

BuildUrl ( System.UrlInfo current, string area, string controller, string action, NameValueCollection queryStringParams ) : string

Builds an URL using the area name, controller name, action name, and a querystring name value collection.

DefaultUrlBuilder ( ) : System

Initializes a new instance of the DefaultUrlBuilder class.

Service ( IServiceProvider provider ) : void

Services the specified provider.

Protected Methods

Method Description
InternalBuildUrl ( string area, string controller, string action, string protocol, string port, string domain, string subdomain, string appVirtualDir, string extension, bool absolutePath, bool applySubdomain, string suffix ) : string

Internals the build URL.

InternalBuildUrl ( string area, string controller, string action, string protocol, string port, string domain, string subdomain, string appVirtualDir, string extension, bool absolutePath, bool applySubdomain, string suffix, string basePath ) : string

Internals the build URL.

Private Methods

Method Description
InternalBuildUrlUsingBasePath ( string action, string area, string basePath, string controller ) : string

Internals the build URL using base path.

InternalBuildUsingAppVirtualDir ( bool absolutePath, string action, bool applySubdomain, string appVirtualDir, string area, string controller, string domain, string port, string protocol, string subdomain ) : string

Internals the build using app virtual dir.

Method Details

BuildUrl() public method

Builds the URL using the current url as contextual information and a parameter dictionary.

Common parameters includes area, controller and action, which outputs /area/controller/name.extension

Please note that if you dont specify an area or controller name, they will be inferred from the context. If you want to use an empty area, you must specify area=''. This is commonly a source of confusion, so understand the following cases:

UrlInfo current = ... // Assume that the current is area Admin, controller Products and action List BuildUrl(current, {action: 'view'}) // returns /Admin/Products/view.castle BuildUrl(current, {controller: 'Home', action: 'index'}) // returns /Admin/Home/index.castle BuildUrl(current, {area:'', controller: 'Home', action: 'index'}) // returns /Home/index.castle

The querystring parameter can be a string or a dictionary. It appends a query string to the url: /area/controller/name.extension?id=1

The absolute parameter forces the builder to output a full url like http://hostname/virtualdir/area/controller/name.extension

The encode parameter forces the builder to encode the querystring /controller/name.extension?id=1&name=John which is required to output full xhtml compliant content.

public BuildUrl ( System.UrlInfo current, IDictionary parameters ) : string
current System.UrlInfo The current Url information.
parameters IDictionary The parameters.
return string

BuildUrl() public method

Builds an URL using the controller name and action name.
public BuildUrl ( System.UrlInfo current, string controller, string action ) : string
current System.UrlInfo The current Url information.
controller string The controller.
action string The action.
return string

BuildUrl() public method

Builds an URL using the controller name, action name, and a querystring dictionary.
public BuildUrl ( System.UrlInfo current, string controller, string action, IDictionary queryStringParams ) : string
current System.UrlInfo The current Url information.
controller string The controller.
action string The action.
queryStringParams IDictionary The query string params.
return string

BuildUrl() public method

Builds an URL using the controller name, action name, and a querystring name value collection.
public BuildUrl ( System.UrlInfo current, string controller, string action, NameValueCollection queryStringParams ) : string
current System.UrlInfo The current Url information.
controller string The controller.
action string The action.
queryStringParams System.Collections.Specialized.NameValueCollection The query string params.
return string

BuildUrl() public method

Builds an URL using the area name, controller name and action name.
public BuildUrl ( System.UrlInfo current, string area, string controller, string action ) : string
current System.UrlInfo The current Url information.
area string The area.
controller string The controller.
action string The action.
return string

BuildUrl() public method

Builds an URL using the area name, controller name, action name, and a querystring dictionary.
public BuildUrl ( System.UrlInfo current, string area, string controller, string action, IDictionary queryStringParams ) : string
current System.UrlInfo The current Url information.
area string The area.
controller string The controller.
action string The action.
queryStringParams IDictionary The query string params.
return string

BuildUrl() public method

Builds an URL using the area name, controller name, action name, and a querystring name value collection.
public BuildUrl ( System.UrlInfo current, string area, string controller, string action, NameValueCollection queryStringParams ) : string
current System.UrlInfo The current Url information.
area string The area.
controller string The controller.
action string The action.
queryStringParams System.Collections.Specialized.NameValueCollection The query string params.
return string

DefaultUrlBuilder() public method

Initializes a new instance of the DefaultUrlBuilder class.
public DefaultUrlBuilder ( ) : System
return System

InternalBuildUrl() protected method

Internals the build URL.
protected InternalBuildUrl ( string area, string controller, string action, string protocol, string port, string domain, string subdomain, string appVirtualDir, string extension, bool absolutePath, bool applySubdomain, string suffix ) : string
area string The area.
controller string The controller.
action string The action.
protocol string The protocol.
port string The port.
domain string The domain.
subdomain string The subdomain.
appVirtualDir string The app virtual dir.
extension string The extension.
absolutePath bool if set to true [absolute path].
applySubdomain bool if set to true [apply subdomain].
suffix string The suffix.
return string

InternalBuildUrl() protected method

Internals the build URL.
protected InternalBuildUrl ( string area, string controller, string action, string protocol, string port, string domain, string subdomain, string appVirtualDir, string extension, bool absolutePath, bool applySubdomain, string suffix, string basePath ) : string
area string The area.
controller string The controller.
action string The action.
protocol string The protocol.
port string The port.
domain string The domain.
subdomain string The subdomain.
appVirtualDir string The app virtual dir.
extension string The extension.
absolutePath bool if set to true [absolute path].
applySubdomain bool if set to true [apply subdomain].
suffix string The suffix.
basePath string The base path.
return string

Service() public method

Services the specified provider.
public Service ( IServiceProvider provider ) : void
provider IServiceProvider The provider.
return void