【问题标题】:Redirection to external page within web forms application重定向到 Web 表单应用程序中的外部页面
【发布时间】:2017-02-20 14:17:45
【问题描述】:

我有一个 WebForms 应用程序 (.Net Framework 4.5.2)。我需要将一些页面重定向到外部网页示例 www.google.com

我尝试修改路线

public class Global : HttpApplication
    {
        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }

        private void RegisterRoutes(RouteCollection routes)
        {

        }
    }

我需要知道

  • 最好的方法是什么?
  • 如何更改我的代码来完成这项任务?

谢谢,

【问题讨论】:

  • 你可以只使用 Response.Redirect 方法
  • @Sergey 我需要一个全局路由配置

标签: c# asp.net .net redirect webforms


【解决方案1】:

我可能会为此使用IIS Url Rewrite。它使您能够在 web.config 中添加重写/重定向,例如:

<rule name="Rule1">
      <match url="somefunpage"/>
      <conditions>
        <add input="{HTTP_HOST}" pattern="mydomain.com"/>
      </conditions>
      <action type="Rewrite" url="http://www.otherdomain.com/" />
</rule>

您还可以使用正则表达式、通配符等。它非常强大。

【讨论】:

    猜你喜欢
    • 2016-10-06
    • 1970-01-01
    • 2017-11-10
    • 2013-09-21
    • 1970-01-01
    • 2018-08-08
    • 1970-01-01
    • 2013-03-11
    • 1970-01-01
    相关资源
    最近更新 更多