views:

42

answers:

3

I noticed similar questions to what I have to ask but I feel I haven't really had my question answered.

I created an admin panel for a client. He has the ability to create Destinations (i.e. Rome, Barcelona, Cancun)

All the information for each destination is dynamic and currently looks like this:

/Destination.aspx?id=1

I would like it to look like this:

/Rome/ or /Cancun/

Is this plausible?

A: 

Check the ASP MVC Framework here. With the MVC framework is very easy to have a RESTful interface. With the framework you could be able to use URL "directories" as parameters.

You could be able to have something like /Vacation/Places/Cancun and under the Vacation controller you could have a method like:


 public void Places(string place)
 {
     if(place.Equals("Cancun"))
     {
              return View("Cancun");
     }
     else if(place.Equals("Puerto Rico"))
     {
         .......
     }
     ...............
}
Freddy
He already implemented the site.
SLaks
A: 

You should use ASP.Net Routing, which can be used independently of the MVC framework.

SLaks
+1  A: 

Yes, it's quite possible. If you use the routing feature in ASP.NET, then it actually pretty easy to get it working (routing is not just for MVC, you know!)

In Global.asax.cs:

protected void Application_Start(object sender, EventArgs e)
{
    RegisterRoutes(RouteTable.Routes);
}

public static void RegisterRoutes(RouteCollection routes)
{
    routes.MapPageRoute("",
        "Destinations/{name}",
        "~/Destinations.aspx");
}

Then in your destinations page, you access the parameter like so:

private void Destinations_Load(object sender, EventArgs e)
{
    string destinationName = Convert.ToString(RouteData.Values["name"]);
    // load destination with name destinationName...
}
Dean Harding
Hmm..still a bit unclear. I created App_Code/Global.asax.cs and added the upper code. Then in Destination.aspx.cs I added the latter code and it errors under RouteData saying i can't convert an object to a string.
Bry4n
Actually I fixed the error but I'm not sure if the Global page is even being called or what I am supposed to do with the Destinations_Load code
Bry4n
@Bry4n: how does your normal Destinations.aspx page work? You take the ID and load the information from the database or something I would guess. In this case, you're loading the information based on the name instead of the identifier, but it's the same basic principle.
Dean Harding
Yeah I use this "int q = Convert.ToInt32(Request.QueryString["id"]);" However when you type in /Rome/ your supposed to go to Destination?id=2 or whatever but the URL at the top still says /Rome/.I also changed it to routes.MapPageRoute("","{Destination}","~/Destinations.aspx"); if that is permitted?Sorry for being so confused I just haven't worked with this before and not quite sure what step I am missing or not taking.
Bry4n
Also I am thinking that the pages aren't even loading Destions_Load because the Global.asax.cs isn't being imported or included anywhere
Bry4n
Ah after an hour I figured it out, thank you so much!
Bry4n