Reputation: 417
I want to read a script tag as below:
<script type="text/javascript"> window.something || function (e, t) {....</script>
from app settings file as
<add key="SomeScripts" value="<script type="text/javascript"> window.something || function (e, t) {....</script>"/>
However I get error and I cant add script tags.Is there any other best way of doing this?
Thanks, Suhas
Upvotes: 0
Views: 356
Reputation: 38618
It is not a good pratice to do this. You could just have a bool value in the appSettings and check if it is true to generate the script on the page. For sample:
<add key="SomeScripts" value="true" />
And in the webpage (I am not sure if it is mvc or webforms).
if (bool.Parse(ConfigurationManager.AppSettings["SomeScripts"]))
{
// generate the script here...
}
If you have it in multiple places, and, it is a MVC application, you could make a PartialView
and just put it in the Shared
to call from everywhere. In webforms, create a web user control
(.ascx
file) and call from everywhere.
Upvotes: 2