没有封闭的循环可以打破或继续 [英] No enclosing loop out of which to break or continue

查看:514
本文介绍了没有封闭的循环可以打破或继续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我将此代码放在Glabal.asax中但是我收到此错误:

没有封闭的循环可以打破或继续



这是gloabal.asax文件中的代码:



Hi I am placing this code in Glabal.asax but I am getting this error:
No enclosing loop out of which to break or continue

This is the code in the gloabal.asax file:

protected void Application_BeginRequest(Object sender, EventArgs e)
    {
        HttpApplication app;
        app = (HttpApplication)sender;
        if (Request.Url.Scheme == "http")
            {
                var path = "https://www.new-url.com";

                Response.Status = "301 Moved Permanently";

                Response.AddHeader("Location", path);
                break;
            }
  
}





有人可以帮忙解决这个问题吗?顺便提一句,错误是指向break keywok。



Please can someone help fixing this?By the way the error is pointing to the break keywok.

推荐答案

错误消息说明了一切: break 只能用于退出一个循环,因为你的代码没有循环,所以你不能使用它。如果要退出该功能,请使用 return
The error message says it all: break can only be used to exit a loop, since your code has no loop then you cannot use it. If you want to exit the function then use return.


这篇关于没有封闭的循环可以打破或继续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆