I am trying to set up dynamic routes in an MVC app, and I have this so far...
string conString = "YATAYATAYATA";
SqlConnection con = new SqlConnection(conString);
SqlCommand cmd = new SqlCommand();
// Retrieve routes from database
cmd.CommandText = "SELECT R.*,S.* FROM Routes R INNER JOIN Sites S ON S.ID = R.SiteID WHERE S.ID = 1";
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
routes.MapRoute(
rdr["name"].ToString(), // Route name
rdr["url"].ToString(), // URL with parameters
new
{
controller = rdr["controller"].ToString(), // Controller name
action = rdr["action"].ToString(), // Action name
id = UrlParameter.Optional // Parameter defaults
}
);
}
And that is working great for now, the only issue I am having is that I would like to have the ability to specify a comma delimited list of optional arguments in the database that I could pull out like...
Array optParams = rdr["parametersOpt"].ToString().Split(',');
But I was not sure how to stick those params into the route object properly. Could just be a minor C# syntax I am not familiar with.