How to use a web.config variable in an HTML header? - html

I have this variable defined in my web.config file :
<appSettings>
<add key ="version" value="123"/>
</appSettings>
and I am using it in my aspx pages' headers without problem:
<link rel="stylesheet" type="text/css" href="../css/style.css?<%= ConfigurationManager.AppSettings["version"] %>"/>
But this doesn't seem to work in a regular HTML page.
What is the correct way of using a web.config variable in straight HTML ?

Server code (for instance what you have in the <%%>) can't be executed on static pages.
You need to append this manually in your static pages, or convert them to dynamic pages (.aspx).
<%%> stands for:
<script runat="server"></script>
In a static page which is not routed through the ASP.NET engine, this will not do anything and will not get converted to server code.

Related

How can I use an appSetting parameter (located in web.config) in my .master template

appSetting parameters
I have a value within app settings that I would like to use in my master page file but I think I am using the wrong syntax. Please bear with me because I am very new to Umbraco
My Web.config code is
<appSettings>
<add key="myKey" value="7829e" />
</appSettings>
The code within my master page is
<umbraco:Macro runat="server" language="cshtml">
#AppSetting.myKey
</umbraco:Macro>
It's not Umbraco related at all, you should be able to do
ConfigurationManager.AppSettings["key"]
Just like you would in standard ASP.NET.

How to create global variables to share between HTML pages

Hi I am currently working on porting over an application to a new server and I each time I move the application to a new directory I have to manually go in and change all of the img, src, and script tags within the html pages. This is becoming very tedious because there are over 30 different pages.
Is the anyway to create a configuration file that holds global variables that can then be included at the top of every HTML file? For example, if I change the path to a script, the only change I would have to make is in the configuration file and not every separate html file.
edit to clarify:
Currently I have hard coded scipt/img/scr tags that look like this:
<link rel="stylesheet" type="text/css" href="/app/returning/html/returning.css" />
I was hoping I could make the href value a variable in a separate file that can be included at the top of every page and it would look something like this:
<link rel="stylesheet" type="text/css" href="(variable from configuration file here)" />
You can create another javascript file with an object with all settings/configurations, and include it in every HTML page.
Something like:
var settings = {
applicationName : "TEST",
IsInDebug : true
};

Link to primefaces theme stylesheet is missing session id

I've added a primefaces theme to the web.xml...
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>le-frog</param-value>
</context-param>
... and get a link to the stylesheet in the head ...
<link type="text/css" rel="stylesheet" href="/pos2hue/javax.faces.resource/theme.css.jsf?ln=primefaces-le-frog" />
...which would be correct, if we wouldn't use single-sign-on, which redirects all URLs without a sessionid to the login screen. So the stylesheet resolves to:
<HTML><HEAD><TITLE>HTTP Post Binding (Request)</TITLE></HEAD><BODY Onload="document.forms[0].submit()"><FORM METHOD="POST" ACTION="https://configured.identity.url"><INPUT TYPE="HIDDEN" NAME="SAMLRequest" VALUE="..."/></FORM></BODY></HTML>
Other links coming from primefaces are OK, for example:
<script type="text/javascript" src="/contextroot/javax.faces.resource/jsf.js.jsf;jsessionid=eo0Oo0oK37AUm7bNOaFqdrB-?ln=javax.faces"></script>
As additional info I have to add:
session mode in web.xml is set to "URL" (i don't want to change that)
<session-config>
<tracking-mode>URL</tracking-mode>
</session-config>
for single-sign-on we use picketlink (i have a picketlink.xml in the WEB-INF folder)
web server is JBoss EAP 6.1
Any ideas, how i could
make primefaces add the sessionid to the stylesheet href?
make an exclusion to the single-sign-on mechanism?
or make it work otherwise?
Adding the stylesheet directly is possible, but unwanted, because we use a JSF2 template for all applications, but i want to configure it for one application only.
Thank you in advance!

Generating a pdf-file out of a twig template

I want to generate a pdf (an invoice as letter) out of a twig template. The template uses a css and contains a header with a logo (png-image) and a footer, which should appear at the bottom of the document.
I tried it with the KnpSnappyBundle, but this doesn't work (css only works inline, images are not rendered..., etc.). Are there any other tools to generate a pdf?
With Java I used jasper-reports (really cool), isn't there anything similar for php?
I have used KnpSnappyBundle to generate pdf before, and it worked with external css files, thought there's is some diffrence bettween regular tempaltes:
When linking asset you have to provide absolute path:
<link type="text/css" rel="stylesheet" href="{{ asset('css/css.css', null, true) }}" />
I didn't needed images files, but I think it should work the same, also you need to use "renderView" method instead of "render".
$pdf = $this->renderView('**:**:tempalte.html.twig', array());
After that you just simple use:
$file = $this->container->get('knp_snappy.pdf')->getOutputFromHtml(pdf);
The answer is: The server startet via
php app/console server:run
is single-threaded, so there is no chance, to get a response, when requesting an image or css-file...

Razor RenderPage my.js without HttpException

Suppose I want to render javascript from an external file inline into my layout file for performance reasons.
If I use the following Razor code
<script>
#RenderPage("~/Content/my.js")
</script>
results in
Server Error in '/' Application.
The following file could not be
rendered because its extension ".js" might not be supported:
"~/Content/my.js".
If I merely rename my javascript file to my.js.cshtml
<script>
#RenderPage("~/Content/my.js.cshtml")
</script>
The peasants rejoice.
The question:
Is there any simple way for me to prevent RenderPage from nagging such that I can tell it that the .js extension is fine?
With some feedback from #choudeshell one potential solution is:
<compilation debug="true" targetFramework="4.5">
<buildProviders>
<remove extension=".js"/>
<add extension=".js" type="System.Web.WebPages.Razor.RazorBuildProvider,
System.Web.WebPages.Razor"/>
</buildProviders>
</compilation>
What type of side effects would there be from removing whatever the default is for .js, any?