我有想出用于以下的溶液的问题。我得到了我最近从Web形式MVC升级了博客。博客是在两个瑞典avalible和英语在两个不同的域和在IIS同一网站正在运行。

的问题是,我想在这两个网站的语言特定的网址,如:

英文: http://codeodyssey.com /存档/ 2009/1/15 /码奥德赛最下一章节

瑞典: http://codeodyssey.se/arkiv / 2009/1/15 /代码奥德赛-NASTA-kapitel

目前我有此通过上取决于哪个域被称为每个请求注册所述RouteTable工作。我的Global.asax看起来是这样的(不是整个代码):

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    string archiveRoute = "archive";

    if (Thread.CurrentThread.CurrentUICulture.ToString() == "sv-SE")
    {
        archiveRoute = "arkiv";
    }

    routes.MapRoute(
        "BlogPost",
        archiveRoute+"/{year}/{month}/{day}/{slug}",
        new { controller = "Blog", action = "ArchiveBySlug" }
        );

    routes.MapRoute(
        "Default",                                              // Route name
        "{controller}/{action}/{id}",                           // URL with parameters
        new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
    );

    routes.MapRoute(
        "404-PageNotFound",
        "{*url}",
        new { controller = "Error", action = "ResourceNotFound" }
    );

}

void Application_BeginRequest(object sender, EventArgs e)
{

    //Check whcih domian the request is made for, and store the Culture
    string currentCulture = HttpContext.Current.Request.Url.ToString().IndexOf("codeodyssey.se") != -1 ? "sv-SE" : "en-GB";

    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(currentCulture);
    Thread.CurrentThread.CurrentUICulture = new CultureInfo(currentCulture);

    RouteTable.Routes.Clear();

    RegisterRoutes(RouteTable.Routes);

    Bootstrapper.ConfigureStructureMap();

    ControllerBuilder.Current.SetControllerFactory(
        new CodeOdyssey.Web.Controllers.StructureMapControllerFactory()
        );
}

protected void Application_Start()
{

}

这工作的时刻,但我知道这不是一个很好的解决方案。说明了这个应用程序时,我已经收到“项目已被添加,关键在字典”的错误,它似乎并不有时稳定。

我想,他们应该而且不必清除它们在每次请求喜欢我现在所做的只建立我的路线在Application_Start。问题是,在请求对象不存在,并且我不知道哪个语言特定路由的我应该登记的方法。

一直念叨的AppDomain,但无法找到如何使用它在网站上的例子很多。 I'we一直在思考的明星是这样的:

protected void Application_Start()
{
   AppDomain.CreateDomain("codeodyssey.se");
   AppDomain.CreateDomain("codeodyssey.com");
}

然后在注册每个应用程序域中的每个网站的路线和发送请求根据网址其中之一。找不到有关如何使用应用程序域以这种方式工作的任何例子。

我是否完全关闭跟踪?还是有这个更好的解决办法?

有帮助吗?

解决方案

在ASP.Net运行时管理的AppDomain给你,所以它可能不是一个好主意,在你的代码中创建应用程序域。

不过,如果可以的话,我会建议为 http://codeodyssey.com 创建多个IIS应用程序(一个一个用于 http://codeodyssey.se )。在磁盘上的同一个目录指向这两个应用程序。这会给你你正在寻找这两个应用程序域。

然后,在你的Application_Start代码,你可以通过检查域和建立相应的路由。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top