False positive on S1075 in ASP.NET MVC with ~/ paths

When using Server.MapPath("~/ ...") to map a relative path to the server root directory, SonarLint raises an “S1075: Refactor your code not to use hardcoded absolute paths or URIs”.

~/ paths are not absolute by their very nature.

Running SonarLint on Visual Studio 2015 Professional, ASP.NET MVC 5

Hi @Kristian_Williams,

Thanks for the feedback.
I have created a ticket on our backlog (here).

Out of curiosity, can you think of other methods than MapPath where you would use ~?

Cheers,
Amaury

I’m getting similar “Warning” for StyleBundle & Include methods used in BundleConfig.cs.

Warning:
Code: S1118
Description: Refactor your code not to use hardcoded absolute paths or URIs.

Example:
bundles.Add(new StyleBundle("~/content/custom")
.Include("~/Content/stylesheets/style.css"));

Using Sonar Lint (v4.8.0.4040) in VS 2017 (v15.9.8) for ASP.MVC (v5.2.7)

thanks @itbharsh I’ve opened issue #2357