I am trying to redirect a page reading the url from the config file.
However, when I try this:
<script type="text/javascript">
<%string redirectUrl = System.Web.Configuration.WebConfigurationManager.AppSettings["RedirectURL"];%>
window.parent.location.replace("<%=redirectUrl%>");
</script>
the alligator tags <% %> are Not being highlighted, and when I run I get the following error in the yellow screen:
the controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
What am I doing wrong??
Thanks!
Edit:
It does work if I just put the url straight into the code, as in
window.parent.location.replace("http://theurl.com");
but I need to change this depending on other things, so I need it to be in the config :S
You’re probably including the block inside a
block. If you want to use <% %> blocks you need to remove the runat=”server” from the head tag but then you’ll lose the Page.Title and some other features.
In your particular case, doing
should fix the problem, i.e. get rid of the <% %> tags.