Routing and Redirecting in Sitefinity
Hello all
I have a need to have a kind of routing/redirecting page where I can look at the querystring and based off of what is in there route the user to another page. So for example if I had a query string like this:
mysite.com/Home/johnsmith
I would have the Home page be my redirection page and based off of the value of "johnsmith" I would then redirect the user to John Smiths page.
In asp.net mvc this is very easy to do. However I am just getting my feet wet with Sitefinity so I have no idea how or if this can be done. I've Googled it quite a bit and I don't think I am asking the question correctly since I can't find anything.
Any help would be much appreciated. Thanks in advance!
-MacKenzie
Hi
It is acctually pretty easy to do.
1) Create a page in sitefinity, in you example it will be called home page.
2) Create a user control, register it in sitefinity and drop it on the home page.
3) In your user control you can capture the parameters the following way:
Include the following namespace:
using Telerik.Sitefinity.Web;
protected void Page_Load(object sender, EventArgs e)
if (!this.IsPostBack)
var parms = (string[])this.Page.Request.RequestContext.RouteData.Values["Params"];
if (parms != null)
string name = parms[0];
if(name == 'johnsmith')
// This will tell sitefinity that parameters resolved
// If this is not called, then you will get a 404 error
RouteHelper.SetUrlParametersResolved(true);
Response.Redirect("johnsmithpageurl");
In this url mysite.com/Home/johnsmith. johnsmith will become a parameter
You can send multiple parameters, for example mysite.com/Home/john/smith will send two parameters to mysite.com/Home page
You can loop through those parameters:
for (int i = 0; i < parms.Length; i++)
switch(params[i])
case "johnsmith":
i++;
// Get Value
valueVariable = parms[i];
break;
case "othername":
i++;
// Get Value
valueVariable = parms[i];
break;
string firstName = parms[0];
string lastName = parms[1];