PDA

View Full Version : Passing parameters with setresult


stephenro
08-19-2005, 03:05 PM
When using SetResult, is there a way to pass querystring parameters?

Thanks

Steve

Aleks Seovic
08-19-2005, 04:32 PM
Yes, there is.

First you need to define your result to expect paramaters. There are two ways of doing this, either by explicitly configuring result object or by using shortcut mechanism:


<object id="testResult1" type="Spring.Web.Support.Result, Spring.Web">
<property name="TargetPage"><value>UserRegistration.aspx</value></property>
<property name="Mode"><value>Redirect</value></property>
<property name="Parameters">
<dictionary>
<entry key="literal"><value>My Test Literal</value></entry>
<entry key="name"><value>${UserInfo.FullName}</value></entry>
<entry key="host"><value>${Request.UserHostName}</value></entry>
</dictionary>
</property>
</object>



or



<property name="Results">
<dictionary>
<entry key="userSaved">
<ref object="testResult2"/>
</entry>
<entry key="shortRedirect">
<value>redirect:UserRegistered.aspx?literal=My Literal,name=${UserInfo.FullName}&amp;host=${Request.U serHostName}</value>
</entry>
<entry key="shortTransfer">
<value>transfer:UserRegistered.aspx?literal=My Literal,name=${UserInfo.FullName},user=${UserInfo} ,host=${Request.UserHostName}</value>
</entry>
</dictionary>
</property>



Obviously, shortcut is much more convinient, but explicit result declaration is useful for global results such as home page for example, because you only need to define it once and reference it many times as in the first result entry above.

One caveat is that if you are using shorthand expression you need to escape ampersand character in the query string or to use comma instead -- it will work either way and comma is a bit more convinient although somewhat non intuitive.

Second thing to keep in mind is that paramaters will be passed differently based on result mode -- they will be passed as a query string for redirects and as entries within HttpContext.Items collection for transfers, in which case you don't have the type limitation that query string has.

Finally, placeholder parameters (${param}) will be resolved in the context of the page that is setting the result. That means that in the example above page where results are configured needs to expose UserInfo property in order for the results to work.

HTH,

Aleks