繁体   English   中英

aspx页面重定向到新页面

[英]aspx page to redirect to a new page

将浏览器重定向到带有ASPX页面的新页面需要什么代码?

我已经在我的页面default.aspx上尝试过此操作:

<% Response.Redirect("new.aspx", true); %>

要么

<%@ Response.Redirect("new.aspx", true); %>

并且这些导致未确定的服务器错误。 我看不到错误代码; 因为服务器不在我的控制范围内,并且错误不公开。

请提供从页面第1行到末尾所有必要的代码,我将非常感谢。

<%@ Page Language="C#" %>
<script runat="server">
  protected override void OnLoad(EventArgs e)
  {
      Response.Redirect("new.aspx");
  }
</script>

您也可以使用meta标记在html中实现此功能:

<html>
<head>
  <meta http-equiv="refresh" content="0;url=new.aspx" />
</head>
<body>
</body>
</html>

达林的答案很棒。 它创建一个302重定向。 这是修改后的代码,以便创建永久的301重定向:

<%@ Page Language="C#" %>
<script runat="server">
  protected override void OnLoad(EventArgs e)
  {
      Response.RedirectPermanent("new.aspx");
      base.OnLoad(e);
  }
</script>

如果使用的是VB,则需要删除分号:

<% Response.Redirect("new.aspx", true) %>

或者,您可以使用javascript重定向到另一个页面:

<script type="text/javascript">
    function toRedirect() {
        window.location.href="new.aspx";
    }
</script>

从客户端(例如:body标签的onload事件)或使用以下命令从服务器调用此toRedirect()函数:

ClientScript.RegisterStartupScript(this.gettype(),"Redirect","toRedirect()",true);

即使您不控制服务器,也可以通过将以下行添加到项目中的Web.config文件(在<system.web>以下)中来查看错误消息:

<customErrors mode="off" />

重定向aspx:

<iframe>

    <script runat="server">
    private void Page_Load(object sender, System.EventArgs e)
    {
    Response.Status = "301 Moved Permanently";
    Response.AddHeader("Location","http://www.avsapansiyonlar.com/altinkum-tatil-konaklari.aspx");
    }
    </script>

</iframe>

在ASP.NET中的一种特殊情况下,如果您想知道该页面是否由指定的.aspx页面而不是另一个页面重定向,只需将信息放在会话名称中,并在接收的Page_Load事件中采取必要的措施。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM