Creating Application/Virtual Directories in a site that POINT to that site to simulate multiple sites. Good idea?
We need a way to say
www.site.com/india www.site.com/asia www.site.com/usa etc...
But we want all these requests to point back to www.site.com and not have to physically create the files and directories for every type of site... so if I just 开发者_JS百科create a virtual directory (www.site.com/india) and point it to www.site.com... then I figure I can look at the URL and set some parameters/text/images accordingly to fill out the template...
Does this make sense? Or are there issues with web.configs ? OR a better way
I would encourage you to consider Routing, as demonstrated here: http://www.asp.net/mvc/tutorials/asp-net-mvc-routing-overview-cs
The given sample, repeated here so you can (hopefully) see the relevance, is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace MvcApplication1
{
// Note: For instructions on enabling IIS6 or IIS7 classic mode,
// visit http://go.microsoft.com/?LinkId=9394801
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
}
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
}
}
}
By similar methods, you can merely extract the information you need
The first example was for MVC Routing, to do webforms routing you should look here http://msdn.microsoft.com/en-us/library/cc668202(VS.90).aspx and here's a (very limited) example:
public static void RegisterRoutes(RouteCollection routes)
{
routes.Add("BikeSaleRoute", new Route
(
"bikes/sale",
new CustomRouteHandler("~/Contoso/Products/Details.aspx")
));
}
Using a custom routehandler that they build in the code. Routehandlers are easy to use, once you get the hang of it. And they allow you more expressiveness.
I think you'll find that localizing the same site five ways without having different web.configs pointing you to your localization files will be difficult.
What I would do is have www.site.com's index wither automatically discover the client's location or ask them what version of the site they want. Then, refer them to a default.aspx under that site's virtual directory, that uses a common set of your custom web controls, localized according to the resource file referenced in that site's web.config. That way, all you'll need to copy is the site skeleton, which can be as little as the index.aspx.
If the site is mostly aspxs, this isn't going to work as well. In that case, I would do the website selection as before, but use a query string to keep track of client location and thus localization. That should still allow you to bring up the correct localization settings.
No, please promise me not to create a virtual directory for each country in the world. Checkout routing instead. And here are some other examples.
Consider using routing or even better MVC if you haven't written the sites already. You should definitely NOT be creating multiple virtual directories - it would be a nightmare to maintain
精彩评论