简体   繁体   English

Default.aspx重定向

[英]Default.aspx redirect

I have a default.aspx page like this with the goal of redirecting differently based on the host header. 我有一个default.aspx页面,其目标是根据主机头进行不同的重定向。

<%
if(System.Web.HttpContext.Current.Request.Url.Host == "xxx.xxx.com")
{
response.redirect ("place/subplace/xxx.aspx")
}
else
{
response.redirect ("place/xxx.aspx")
}
%>

but it is giving me the error "Compiler Error Message: BC30201: Expression expected." 但它给了我错误“编译器错误消息:BC30201:预期的表达式。”

What am I doing wrong? 我究竟做错了什么?

In C# expressions are terminated with a semicolon ; 在C#中,表达式以分号结尾;

if (System.Web.HttpContext.Current.Request.Url.Host == "xxx.xxx.com")
{
    Response.Redirect("place/subplace/xxx.aspx"); <-- here
} 
else
{
    Response.Redirect("place/xxx.aspx"); <-- and here
}

and C# is case-sensitive. C#区分大小写。 Both Response and Redirect start with a capital letter. ResponseRedirect以大写字母开头。

Edit: Since you now tagged this as VB.Net 编辑:由于您现在将此标记为VB.Net

Your code is no valid VB.net code. 您的代码不是有效的VB.net代码。 If it were it should read like the following: 如果是这样,则应如下所示:

If System.Web.HttpContext.Current.Request.Url.Host = "xxx.xxx.com" Then
    Response.Redirect("place/subplace/xxx.aspx")
Else
    Response.Redirect("place/xxx.aspx")
End If

When the compiler gives the error "expression expected" , it's usually a synthax error. 当编译器给出“期望的表达式”错误时,通常是synthax错误。 Add a semi-column(;) after response.redirect? 在response.redirect之后添加一个半列(;)?

The following works for me: 以下对我有用:

protected void Page_Load(object sender, EventArgs e)
    {
        if(System.Web.HttpContext.Current.Request.Url.Host == "xxx.xxx.com")
        {
            Response.Redirect("place/subplace/xxx.aspx");
        }
        else
        {
            Response.Redirect("place/xxx.aspx");
        }
    }

This worked for me. 这对我有用。 http://www.w3schools.com/asp/met_redirect.asp http://www.w3schools.com/asp/met_redirect.asp

Using the above link, I wrote the following lines and it executed without any problem. 使用上面的链接,我编写了以下几行,并且执行起来没有任何问题。 Notice there is no semicolon at the end. 请注意,结尾没有分号。 My default.aspx page just contains the following three lines. 我的default.aspx页面仅包含以下三行。

<%
    Response.Redirect("~/portal")
%>

Possible reason is; 可能的原因是; usually language is mentioned at the top of .aspx pages or in the web.config file. 通常在.aspx页面顶部或web.config文件中提到语言。 If language is not mentioned, IIS uses VB.NET to compile the pages and we know that VB.NET doesn't uses semicolons to terminate the statements. 如果未提及语言,则IIS使用VB.NET来编译页面,并且我们知道VB.NET不会使用分号来终止语句。

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

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