代码之家  ›  专栏  ›  技术社区  ›  antpaw

C ASP.NET新用户重定向问题

  •  2
  • antpaw  · 技术社区  · 15 年前

    嘿,我想让这个工作,但我不是一个C程序员。我有这个代码来显示我想做什么。但因为它不起作用。错误:CS1519:令牌无效…

    <%@ Page Language="c#" AutoEventWireup="true" %>
    <script language="C#" runat="server">
        if(Request.ServerVariables["HTTP_HOST"] === "this-domain.com"){
            Response.Redirect("http://other-domain.com", true);
        }
    </script>
    

    Microsoft.NET框架版本:2.0.50727.3603;ASP.NET版本:2.0.50727.3601

    4 回复  |  直到 15 年前
        1
  •  3
  •   Daniel Elliott    15 年前
    Request.ServerVariables["HTTP_HOST"] === "this-domain.com"
    

    应该是

    Request.ServerVariables["HTTP_HOST"] == "this-domain.com"
    

    你需要把整个陈述都放在蜂刺里 <% %>

        2
  •  3
  •   Paul Hiles    15 年前

    尝试将==更改为==

        3
  •  1
  •   Klaus Byskov Pedersen    15 年前

    你需要改变 === == .

        4
  •  1
  •   Vibin Jith    15 年前

    ==不需要,==就足够了。

    去除 脚本标记。 并使用scriptlets ie<%%>

    <%
    
      if(Request.ServerVariables["HTTP_HOST"] == "this-domain.com"){
            Response.Redirect("http://other-domain.com", true);
        }
     %>