Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
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:

C#
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;
            }
  
}


Please can someone help fixing this?By the way the error is pointing to the break keywok.
Posted
Comments
Sergey Alexandrovich Kryukov 2-May-13 9:51am    
It's not "by the way". If you are asking about an error, point the exact line. Same about an exception. You did it, thank you.
—SA

1 solution

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.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 2-May-13 9:52am    
Solved! A 5. :-)
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900