Overview
The Request attribute indicates that the value of this field is maintained in the Request Context.
Usage
This attribute is specified for Property and Field level usage. Members marked with this attribute will be populated with the corresponding value from the request context prior to controller execution, and will have their value propagated to the context after execution has completed.
This attribute is typically used in conjunction with a Provides/Requires/DependsOn attribute. Fields not marked with any of the three, will be defaulted to Provides.
Note that while not recommended, this attribute can be used in conjunction with the Session attribute. In such a case, the values of the two fields are synchronized, with the value of the Session-level field taking priority over the Request-level field.
Name
The name property can be used to redefine the resource name of the context entry bound to this member. The value defaults to the name of the member marked.
Example
The following code demonstrates how to pass a value between two controllers through the request context. Note that by combining the Request and DependsOn attributes, the Home controller notifies the system that if there is a provider of a preferenceReset value, it should run first. In this example, if a request comes in for /default/clear-prefs, the ClearPreferences controller will execute before the Home controller, providing it with true for preferenceReset
[Bind("/default/clear-prefs")]
public class ClearPreferences : AbstractController
{
[Request]
protected bool preferenceReset;
public override void DoProcessRequest(IExecutionContext context)
{
ContentTypeHelper.Instance.SetAsDefault(null);
preferenceReset = true;
}
}
[Bind("/")]
[Bind("/default")]
public class Home : AbstractController
{
[Request, DependsOn]
protected bool preferenceReset;
public override void DoProcessRequest(IExecutionContext context)
{
ContentType def = ContentTypeHelper.Instance.GetLastDefault();
if (def == null || preferenceReset)
{
context.RenderWith("Templates/default.bistro");
return;
}
context.Transfer("/action/search/" + (def.Equals(ContentType.Resume) ? "resume" : "ad"));
}
}