How to create a condition in my web.config file for it to only affect files in the current directory - web-config

Part of my web.config file in the httpdocs directory on my website is below. It works fine for it's main purpose, which is to redirect all files with .php extension to the no-extension version. However, the contact form on my website uses a file called "mailer.php", and my form is not working properly anymore because the "mailer.php" is redirected to just "mailer". My contact form works fine when I remove the code below from the web.config file.
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirecting .php ext" stopProcessing="true">
<match url="^(.*).php"/>
<conditions logicalGrouping="MatchAny">
<add input="{URL}" pattern="(.*).php"/>
</conditions>
<action type="Redirect" url="{R:1}"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
So my question is: how can I change this code so it won't redirect the "mailer.php" to "mailer"? I would like to solve this by adding a condition so the rule only redirects files in the httpdocs directory and not any child or parent directory, since my "mailer.php" file is in a child directory.

Related

PMD: How to exclude a rule imported from a ruleset

We are using PMD to assess the quality of our "main" source code. We have our own customized ruleset that includes some category rulesets and excludes some specific rules.
Simplified example, file called pmd.xml:
<?xml version="1.0"?>
<ruleset name="Main rules"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
<description>Main rules</description>
<rule ref="category/java/bestpractices.xml">
<exclude name="GuardLogStatement"/>
</rule>
<rule ref="category/java/security.xml"/>
</ruleset>
Analysis is launched from gradle, it works fine for our "main" source code.
Now we would like to get another more lenient ruleset for our "test" source code. As we don't want to duplicate our set of rules, what we would like to do is import this main ruleset, and exclude some more rules.
So we basically would like to keep the GuardLogStatement excluded, and also exclude rule UnusedPrivateMethod, with a file looking like this one.
<?xml version="1.0"?>
<ruleset name="Test rules"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
<description>Test rules</description>
<!-- Test rules are based on rules for main -->
<rule ref="./config/pmd.xml">
<exclude name="UnusedPrivateMethod"/>
</rule>
</ruleset>
This doesn't work:
GuardLogStatement is excluded, but
UnusedPrivateMethod still runs.
I don't see any reference in the documentation on how to exclude a rule from a ruleset.
Anyone managed to do something similar?
It turns out this actually works fine.
Pure PEBKAC, the problem was due to my work environment.
I am keeping the question as it demonstrates a nifty way of having a ruleset for the test code derived from the ruleset for the main code.

visual studio code and private nuget

I have a library that comes from a private nuget feed. I have the url and credentials for that but dont know how to connect to the feed properly with visual studio code. I am using dotnetcore framework.
I created a Nuget.Config file in the root of my console application with the feed url and username and password but this didn't seem to pick up the packages from that feed when imputting them in the project.json. Even doing a restore would produce errors.
Does anyone have an example of how they would set up a project to do this? I know it is not normal to have the Nuget.Config file in the project but this is a test project so would not live there once the project got past proof of concept.
My nuget.config looked like this
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="CustomRepo" value="https://nuget.feed/nuget/" />
</packageSources>
<!-- Used to store credentials -->
<packageSourceCredentials>
<CustomRepo>
<add key="Username" value="something" />
<add key="ClearTextPassword" value="thepassword" />
</CustomRepo>
</packageSourceCredentials>
<!-- Used to disable package sources -->
<disabledPackageSources />
</configuration>
Apoligies this is now resolved and working with the nuget.config file in the root folder. I dont know what I did. Only thing I did was re-type the whole xml but dont know what what would have done. Anyway it is working which is great.

How we can use custom settings for sonar in eclipse?

I am using SonarLint for better code. This is using default settings. I have an xml file with following entries.
<profile>
<name>Sonar Way with Custom rules</name>
<language>java</language>
<rules>
<rule>
<repositoryKey>common-java</repositoryKey>
<key>DuplicatedBlocks</key>
<priority>MINOR</priority>
</rule>
<rule>
<repositoryKey>common-java</repositoryKey>
<key>InsufficientBranchCoverage</key>
<priority>MAJOR</priority>
<parameters>
<parameter>
<key>minimumBranchCoverageRatio</key>
<value>65.0</value>
</parameter>
</parameters>
</rule>
<profile>
My question is how I can use this xml as my custom settings for SonarLint.
Thanks
The correct way of doing it is to define a Quality Profile in a SonarQube server with the rules that you want to activate and connect SonarLint to it.
For more information, check the "Connected mode" section for the IDE you are using in http://www.sonarlint.org.

Setting an environment variable in a NuGet.Config file

I have a situation where I want to set the repositoryPath variable of the NuGet.config file to a location relative to the current user's machine. The goal is to have a location where all of the NuGet packages get placed, so that:
They are not located in the solution folder for each of our team projects (ie. /Solution/packages/*)
They are shared across many projects, so that only one copy of that package needs to be installed on the machine.
Ideally, I would like to use a path with an environment variable, such as %APPDATA%, however the NuGet Package Manager doesn't work with this.
My config file looks something like this:
<config>
<add key="repositoryPath" value="C:\External\NuGetPackages" />
<add key="DefaultPushSource" value="\\SourceCode\NuGetPackages\" />
</config>
Where ideally I would like the repositoryPath to work like this:
<add key="repositoryPath" value="%APPDATA%\External\NuGetPackages" />
Things I have tried:
$(APPDATA)
$APPDATA
$Env:APPDATA
The first two of these just result in directories with those names being placed in the same location as the NuGet.config file.
This has been added as a feature in NuGet v3.4+
Variables can now be added in Windows using the standard syntax, eg:
<configuration>
<config>
<add key="repositoryPath" value="%HOME%\NuGetRepository" />
</config>
</configuration>
See https://docs.nuget.org/consume/nuget-config-file#environment-variables-in-configuration

Add HttpModule to web.config in Nop

The issue seems to be that the syntax
<configuration>
<system.webServer>
<modules>
<add name="HelloWorldModule" type="HelloWorldModule"/>
</modules>
</system.webServer>
</configuration>
is looking in the site bin folder, however as far as I can tell nop
commerce only puts a plugins dll in the Plugins folder.
What I've tried, that hasn't worked so far
putting the syntax in the web.config that exists in within the plugin folder
wrapping the syntax in the <location path="..."> tag
I realize that I could pull the class out into it's own project and manually drop the compiled dll into the bin, but I'd like to avoid this.
Has anybody used httpmodules within a Nop Commerce Plugin?