Asp.net重定向到另一个站点

时间:2019-07-03 10:30:52

标签: c# asp.net http-redirect

在我们的项目中,我们使用MapPageRoute

public static class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            var settings = new FriendlyUrlSettings();
            settings.AutoRedirectMode = RedirectMode.Permanent;
            routes.EnableFriendlyUrls(settings);


            routes.IgnoreRoute("{*alljs}", new { allaspx = @".*\.js(/.*)?" });

            routes.MapPageRoute("Landing", "landing/{state}/{city}", "~/landing_test.aspx");
            routes.MapPageRoute("Cremation", "cremation-services", "~/cremations.aspx");
            routes.MapPageRoute("FAQ", "funeral-planning-faq", "~/FAQ.aspx");
            routes.MapPageRoute("Homes", "funeral-homes/{state}/{city}/{id}", "~/viewHome.aspx");
            routes.MapPageRoute("CitySearch", "search/{state}/{city}", "~/areaHomeLists.aspx");
            routes.MapPageRoute("BlankSearch", "search", "~/areaHomeLists.aspx");
            routes.MapPageRoute("About", "about", "~/about.aspx");
        }
    }

当用户在“关于”页面上时,我需要使用301代码重定向到另一个网站。

我尝试将MapPageRoute更改为MapRoute,并创建了RedirectController,但它对我不起作用(或者我不了解它的工作原理)

routes.MapRoute("About", "about.aspx", new {controller = "Redirect", action = "FAQ"});

public class RedirectController : Controller
    {
        public ActionResult Blog()
        {
            return RedirectPermanent("FAQ");
        }
    }

1 个答案:

答案 0 :(得分:0)

我在web.config中添加了规则,现在可以了

<rule name="About reditect" stopProcessing="true">
  <match url="about*" />
  <action type="Redirect" url="https://www.google.com" redirectType="Permanent" />
</rule>