Razor RenderPage my.js without HttpException - razor

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?

Related

Custom coding standard ruleset not working for Code Sniffer in PhpStorm

I have a project in PhpStorm 2019.2.3 for which I want to use a custom coding standard ruleset with PHP Code Sniffer. The Code Sniffer works as expected, when I choose a provided coding standard, but when I change to my custom ruleset, all sniffs disappear.
I copied the whole /PSR2 folder under /PHP_CodeSniffer-3.4.2/src/Standards/, named it PSR2-Custom and edited the contained ruleset.xml to this:
<?xml version="1.0"?>
<ruleset name="PSR2R">
<rule ref="PSR2">
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine" />
<exclude name="PSR2.Classes.ClassDeclaration.OpenBraceNewLine" />
</rule>
<rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie" />
</ruleset>
What I think it does is that it uses the PSR2 coding standard and excludes two of the contained rules, inspired by phpcs: How can I modify PSR2 to check that the brace is on the same line as the method? and https://github.com/squizlabs/PHP_CodeSniffer/issues/703
These are my settings:
A) Settings > Languages & Frameworks > PHP > Quality Tools:
local configuration with path to phpcs.bat (PHP_CodeSniffer-3.4.2, manually downloaded) (as documented)
B) Settings > Editor > Inspections: PHP > Quality tools > PHP Code Sniffer Validation:
-> choosing PSR2 in 'Coding standards' dropdown: sniffs marked
-> choosing PSR2-Custom in 'Coding standards' dropdown: no sniffs marked anymore
I checked similar issues on SO, but non of them helped me with my problem, e.g.
Custom PMD ruleset not working
I can't figure out, where I went wrong. Is my ruleset config buggy? Thanks for helping out.

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.

Accessing "test.html" page from the browser at the following url http://mysharepointservername.com/test.html

Which directory should I use to place test.html to access it via the browser by using the following url:
http://mysharepointservername.com/test.html ?
If I place the file to C:\inetpub\wwwroot\wss\VirtualDirectories\80 , I get 404 not found error.
Is there another directory I should use to place test.html?
Thank you in advance
You can create a module in sharepoint and place test.html under that module.
And in elements.xml write:
Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="CustomPage" Url="">
<File Url="CustomPage\test.html" Name="test.html" Type="Ghostable" />
</Module>
</Elements>
And deploy this module using feature.
In this way you can access the page with http://mysharepointservername.com/test.html

POST verb not allowed

A bit basic, but I have tried some of the methods to tackle the following error but could not get the right solution.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<form method="post">
<input type="text" name="query1"></input>
<input type="text" name="query2"></input>
<input type="submit"></input>
</form>
</body>
</html>
Error on running :
HTTP Error 405.0 - Method Not Allowed
The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.
In the mappings of IIS, I have added the POST method but that did not work!
Suggestions please!
The following code has solved the problem for me(it's for php on iis).
web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers accessPolicy="Read, Execute, Script">
<remove name="PHP55_via_FastCGI" />
<add name="PHP55_via_FastCGI" path="*.php" verb="*" modules="FastCgiModule" scriptProcessor="C:\Program Files (x86)\PHP\v5.5\php-cgi.exe" resourceType="Either" requireAccess="Script" />
<add name="HTML_via_FastCGI" path="*.html" verb="*" modules="FastCgiModule" scriptProcessor="C:\Program Files (x86)\PHP\v5.5\php-cgi.exe" resourceType="Either" requireAccess="Script" />
<add name="HTM_via_FastCGI" path="*.htm" verb="*" modules="FastCgiModule" scriptProcessor="C:\Program Files (x86)\PHP\v5.5\php-cgi.exe" resourceType="Either" requireAccess="Script" />
</handlers>
<security>
<requestFiltering>
<fileExtensions>
<add fileExtension=".php" allowed="true" />
</fileExtensions>
<verbs>
<add verb="POST" allowed="true" />
<add verb="GET" allowed="true" />
<add verb="HEAD" allowed="true" />
<add verb="DELETE" allowed="true" />
<add verb="PUT" allowed="true" />
</verbs>
</requestFiltering>
</security>
</system.webServer>
Without seeing more, this could be a variety of problems. With that in mind, here is a list of possible fixes for your issue:
Cause 1
This problem occurs because the client makes an HTTP request by using
an HTTP method that does not comply with the HTTP specifications.
To resolve this problem, see resolution 1.
Cause 2
This problem occurs because a client makes an HTTP request by sending
the POST method to a page that is configured to be handled by the
StaticFile handler. For example, a client sends the POST method to a
static HTML page. However, pages that are configured for the
StaticFile handler do not support the POST method.
To resolve this problem, see resolution 2.
Resolution 1
Make sure that the client sends a request that contains a valid HTTP
method. To do this, follow these steps:
Click Start, type Notepad in
the Start Search box, right-click Notepad, and then click Run as
administrator.
Note If you are prompted for an administrator password or for a
confirmation, type the password, or provide confirmation. On the File
menu, click Open. In the File name box, type
%windir%\system32\inetsrv\config\applicationhost.config, and then
click Open.
In the ApplicationHost.config file, locate the
tag.
Make sure that all the handlers use valid HTTP methods.
Save the ApplicationHost.config file.
Resolution 2
Send the POST request to a page that is configured to be handled by a
handler other than the StaticFile handler (for example, the ASPClassic
handler). Or, change the request that is being handled by the
StaticFile handler so that it is a GET request instead of a POST
request.
MSDN Source
In my opinion you have 2 errors:
1) If your file extension is *.html change it to for example *.asp, *.php and it will work.
2)The input tag doesn't have closing tag.

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

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.