将我的网站重定向到 mvc 中的默认控制器

Redirect my website to a default controller in mvc

我的项目中有一个名为 Fa 的区域,在我的 fa 区域中,我有一个名为 home 的控制器,在我的控制器中,我有一个名为 index 的动作.

我发布了我的网站,但是当我输入 url 时,我看不到我的网站,因为它应该被重定向到 mywebsite.com/en/home/index。我如何设置这个 url我的 MVC Project

我试过这个,但没用。

var route = routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    ).DataTokens = new RouteValueDictionary(new { area = "fa" });

您需要为默认路由指定命名空间。由于您有多个 HomeController,它需要知道要渲染哪一个。

根据您的意见,您还需要修改默认值。

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { area = "en", controller = "Home", action = "Index", id = UrlParameter.Optional },
    namespaces: new string[] { "UI.Areas.en.Controllers" }
);

您应该使用此代码:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
                routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new {area="fa", controller = "Home", action = "Index", id = UrlParameter.Optional },namespaces: new string[] { "UI.Areas.fa.Controllers"}
            ).DataTokens.Add("area", "fa");