<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://olsh.me/feed.xml" rel="self" type="application/atom+xml" /><link href="https://olsh.me/" rel="alternate" type="text/html" /><updated>2024-09-01T07:42:57+00:00</updated><id>https://olsh.me/feed.xml</id><title type="html">Oleg Shevchenko’s blog</title><subtitle>Hello, I&apos;m Oleg</subtitle><entry><title type="html">Custom error pages configuration in ASP.NET MVC 5 and IIS</title><link href="https://olsh.me/iis/errors/mvc5/2019/08/24/iis-custom-error-page.html" rel="alternate" type="text/html" title="Custom error pages configuration in ASP.NET MVC 5 and IIS" /><published>2019-08-24T10:00:00+00:00</published><updated>2019-08-24T10:00:00+00:00</updated><id>https://olsh.me/iis/errors/mvc5/2019/08/24/iis-custom-error-page</id><content type="html" xml:base="https://olsh.me/iis/errors/mvc5/2019/08/24/iis-custom-error-page.html"><![CDATA[<p>Yeah, this is hard, even Microsoft can’t set up custom error pages properly 
<a href="https://www.microsoft.com/en-us/%20/default.aspx">https://www.microsoft.com/en-us/%20/default.aspx</a></p>

<p>TL;DR here is a demo repository <a href="https://github.com/olsh/mvc5-custom-error-pages-example">https://github.com/olsh/mvc5-custom-error-pages-example</a></p>

<p>There are many posts on the internet how to set up the custom error pages in ASP.NET MVC and IIS. However, some of them doesn’t cover all errors or suggest to have two files for each custom page (<code class="language-plaintext highlighter-rouge">html</code> and <code class="language-plaintext highlighter-rouge">aspx</code>). 
Some articles use client redirect, which is not suitable for SEO.
In this short note, we set up custom errors without code duplication, and all cases will be covered.</p>

<p>First, we need to create <code class="language-plaintext highlighter-rouge">aspx</code> pages for 404 and 500 errors; let’s keep them simple. 
We use <code class="language-plaintext highlighter-rouge">aspx</code> because we need to override <code class="language-plaintext highlighter-rouge">customErrors</code> status code, for some reason it sets it to 200 (OK), 
also both <code class="language-plaintext highlighter-rouge">customErrors</code> and <code class="language-plaintext highlighter-rouge">httpErrors</code> don’t work with <code class="language-plaintext highlighter-rouge">cshtml</code>.</p>

<script src="https://gist.github.com/3b44d8a3b5f0c89b42136ada80d1817f.js?file=404.aspx"> </script>

<script src="https://gist.github.com/3b44d8a3b5f0c89b42136ada80d1817f.js?file=500.aspx"> </script>

<p>Remove <code class="language-plaintext highlighter-rouge">HandleErrorAttribute</code>. We don’t want to use it because it doesn’t support <code class="language-plaintext highlighter-rouge">aspx</code> files.</p>

<p>Add <code class="language-plaintext highlighter-rouge">customErrors</code> to <code class="language-plaintext highlighter-rouge">web.config</code> file, this config is responsible for handling errors which occurred in .NET stack</p>

<script src="https://gist.github.com/3b44d8a3b5f0c89b42136ada80d1817f.js?file=web-1.config"> </script>

<p>Add <code class="language-plaintext highlighter-rouge">httpErrors</code> to <code class="language-plaintext highlighter-rouge">web.config</code>, this one is needed for errors outside .NET stack (for example static files)</p>

<script src="https://gist.github.com/3b44d8a3b5f0c89b42136ada80d1817f.js?file=web-2.config"> </script>

<p>Set .NET Framework version to 4.6.2 or higher. 
This step is important. Otherwise, custom errors won’t work if a URL contains whitespace.</p>

<script src="https://gist.github.com/3b44d8a3b5f0c89b42136ada80d1817f.js?file=web-3.config"> </script>

<p>That’s it!</p>

<p>Here is a demo project <a href="https://github.com/olsh/mvc5-custom-error-pages-example">https://github.com/olsh/mvc5-custom-error-pages-example</a><br />
The configuration was tested on .NET Framework 4.6.2 and IIS 8.5/10.</p>

<p>If you found a mistake or the configuration doesn’t work for you, please let me know.</p>]]></content><author><name></name></author><category term="iis" /><category term="errors" /><category term="mvc5" /><summary type="html"><![CDATA[Yeah, this is hard, even Microsoft can’t set up custom error pages properly https://www.microsoft.com/en-us/%20/default.aspx]]></summary></entry><entry><title type="html">Generate release notes with Jira and TeamCity</title><link href="https://olsh.me/jira/teamcity/octopus/tfs/2018/09/05/teamcity-jira-release-notes.html" rel="alternate" type="text/html" title="Generate release notes with Jira and TeamCity" /><published>2018-09-05T20:00:00+00:00</published><updated>2018-09-05T20:00:00+00:00</updated><id>https://olsh.me/jira/teamcity/octopus/tfs/2018/09/05/teamcity-jira-release-notes</id><content type="html" xml:base="https://olsh.me/jira/teamcity/octopus/tfs/2018/09/05/teamcity-jira-release-notes.html"><![CDATA[<p><em>Update 2019-08-24</em><br />
<em>If you use Jira + TeamCity + Octopus stack. The official Octopus plugin for TeamCity now supports metadata generation, 
give it a try <a href="https://octopus.com/blog/metadata-and-work-items">https://octopus.com/blog/metadata-and-work-items</a></em></p>

<hr />

<p>Recently we switched from TFS to Jira and TeamCity. 
We used to generate release notes with 
<a href="https://marketplace.visualstudio.com/items?itemName=octopusdeploy.octopus-deploy-build-release-tasks">the Octopus extension</a>, 
and it has release notes generation feature out of the box. 
<del>Sadly, the TeamCity plugin does not have the feature, and 
the Octopus team said that they <a href="https://octopusdeploy.uservoice.com/forums/170787-general/suggestions/3052975-include-teamcity-changes-links-with-each-release">are not going to implement it</a>.</del>
Starting from Octopus 2019.4 the official TeamCity plugin supports the metadata generation.</p>

<p>However, the Octopus support sent the link to the 
<a href="https://blogg.bekk.no/generating-a-project-change-log-with-teamcity-and-powershell-45323f956437">excellent article</a> 
which shows how you can generate the release notes with commits using PowerShell.
However, the script doesn’t fit our needs, because we wanted to include linked tasks too, so I extended the script.</p>

<p>The extended script grabs all the changes from a TeamCity build and tries to retrieve the tasks’ 
information from Jira and generates a markdown file with release notes. 
After that, you can publish the generated file to the Octopus server with 
<a href="https://octopus.com/docs/api-and-integration/octo.exe-command-line/creating-releases">octo.exe</a> or 
<a href="https://octopus.com/docs/api-and-integration/teamcity">TeamCity plugin</a>.
I’ve also created a TeamCity meta-runner which <a href="https://confluence.jetbrains.com/display/TCD18/Working+with+Meta-Runner#WorkingwithMeta-Runner-InstallingMeta-Runner">you can use as a build step in TeamCity</a>. 
The source code is available <a href="https://github.com/olsh/teamcity-jira-release-notes/blob/master/GenerateJiraReleaseNotes.xml">here</a>.
The script was tested on Jira 7 and TeamCity 2018.1</p>

<script src="http://gist-it.appspot.com/http://github.com/olsh/teamcity-jira-release-notes/blob/master/GenerateJiraReleaseNotes.ps1"></script>

<p>Hope this script will be useful for someone else.</p>]]></content><author><name></name></author><category term="jira" /><category term="teamcity" /><category term="octopus" /><category term="tfs" /><summary type="html"><![CDATA[Update 2019-08-24 If you use Jira + TeamCity + Octopus stack. The official Octopus plugin for TeamCity now supports metadata generation, give it a try https://octopus.com/blog/metadata-and-work-items]]></summary></entry><entry><title type="html">Monitor vulnerabilities in .NET Core projects with Snyk</title><link href="https://olsh.me/net/core/snyk/2018/07/06/monitor-net-vulnerabilities-with-snyk.html" rel="alternate" type="text/html" title="Monitor vulnerabilities in .NET Core projects with Snyk" /><published>2018-07-06T19:00:00+00:00</published><updated>2018-07-06T19:00:00+00:00</updated><id>https://olsh.me/net/core/snyk/2018/07/06/monitor-net-vulnerabilities-with-snyk</id><content type="html" xml:base="https://olsh.me/net/core/snyk/2018/07/06/monitor-net-vulnerabilities-with-snyk.html"><![CDATA[<p>In this short note, I’ll show how you can continuously monitor dependency vulnerabilities in your project with <a href="https://snyk.io/">Snyk</a>. <br />
So what’s Snyk? Snyk is a service which allows you to detect and monitor vulnerabilities in projects, and it supports various platforms.
For some reason, the documentation for how to set up the scanning for .NET projects almost is not documented, so let’s set up the scanning ourselves.</p>

<ol>
  <li>Install <a href="https://snyk.io/docs/using-snyk/">Snyk CLI</a>
    <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>npm <span class="nb">install</span> <span class="nt">-g</span> snyk
</code></pre></div>    </div>
  </li>
  <li>Copy your API token and add a new environment variable with the name <code class="language-plaintext highlighter-rouge">SNYK_TOKEN</code>, 
you can find it on the <a href="https://snyk.io/account/">account page</a></li>
  <li>Build the testing solution</li>
  <li>Run <code class="language-plaintext highlighter-rouge">monitor</code> command to detect vulnerabilities where <code class="language-plaintext highlighter-rouge">org</code> parameter is your organization name, you can find it on the settings page.
    <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>snyk monitor <span class="nt">--org</span><span class="o">=</span>olsh <span class="nt">--file</span><span class="o">=</span>YourSolution.sln
</code></pre></div>    </div>
  </li>
  <li>At the moment of writing, the is <a href="https://github.com/snyk/snyk/issues/142">an issue with scanning directories with 
multiple package file types</a>
so you should execute monitor command for each project which contains <code class="language-plaintext highlighter-rouge">package.json</code> 
or other package type and specify <code class="language-plaintext highlighter-rouge">obj</code> directories as arguments.
    <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>snyk monitor <span class="nt">--org</span><span class="o">=</span>olsh youproject/obj yourproject2/obg
</code></pre></div>    </div>
  </li>
</ol>

<p>That’s it. Go to your Snyk dashboard and check found vulnerabilities.<br />
You can also execute these steps on CI server to continuously test your projects,
here is an example of a <a href="https://github.com/olsh/curl-to-csharp/blob/master/build.cake">cake script</a> 
which <a href="https://ci.appveyor.com/project/olsh/curl-to-csharp">runs on AppVeryor</a> on each commit and sends the analysis to snyk.</p>]]></content><author><name></name></author><category term="net" /><category term="core" /><category term="snyk" /><summary type="html"><![CDATA[In this short note, I’ll show how you can continuously monitor dependency vulnerabilities in your project with Snyk. So what’s Snyk? Snyk is a service which allows you to detect and monitor vulnerabilities in projects, and it supports various platforms. For some reason, the documentation for how to set up the scanning for .NET projects almost is not documented, so let’s set up the scanning ourselves.]]></summary></entry><entry><title type="html">Importing ReSharper issues to SonarQube</title><link href="https://olsh.me/resharper/sonarqube/2018/06/21/resharper-to-sonarqube.html" rel="alternate" type="text/html" title="Importing ReSharper issues to SonarQube" /><published>2018-06-21T23:43:00+00:00</published><updated>2018-06-21T23:43:00+00:00</updated><id>https://olsh.me/resharper/sonarqube/2018/06/21/resharper-to-sonarqube</id><content type="html" xml:base="https://olsh.me/resharper/sonarqube/2018/06/21/resharper-to-sonarqube.html"><![CDATA[<p><em>Update 2019-08-04</em><br />
<em>If you are on self-hosted SonarQube server, you can consider using <a href="https://github.com/Soloplan/resharper-clt-plugin">the plugin</a></em></p>

<p>In the latest version of SonarQube new fantastic feature was introduced, so-called external analyzers.
The quote from the <a href="https://www.sonarqube.org/sonarqube-7-2/">official site</a>:</p>

<blockquote>
  <p>SonarQube 7.2 introduces a generic way to import issues found by 3rd-party analyzers.
No need to jump from one tool to another, just benefit from a consolidated view in SonarQube. Even better: SonarQube has built-in support for some of the standard analyzers out there.</p>
</blockquote>

<p>At the moment of writing, only <a href="https://docs.sonarqube.org/display/PLUG/SonarTS">TypeScript plugin</a> has out of the box support of the feature. Fortunately, there is <a href="https://docs.sonarqube.org/display/SONAR/Generic+Issue+Data">generic issue data</a> format, which <em>allows importing issues from any analyzer</em>. ReSharper in its turn has a free command-line tool <a href="https://www.jetbrains.com/help/resharper/InspectCode.html">Inspect Code</a> which can analyze projects and produce a report in XML format, so all we have to do is to convert ReSharper format to SonarQube format.</p>

<p>Generate ReSharper report part is simple, just run the Inspect Code tool against your solution:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>InspectCode YouSolution.sln <span class="nt">--swea</span> <span class="nt">-s</span><span class="o">=</span>INFO <span class="nt">-o</span><span class="o">=</span>ReSharperReport.xml
</code></pre></div></div>

<p>For the next step, I wrote a small .NET core <a href="https://github.com/olsh/dotnet-reqube">global tool</a> which can convert ReSharper report to SonarQube format. First, you need to install <code class="language-plaintext highlighter-rouge">dotnet-reqube</code> with the following command.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>dotnet tool <span class="nb">install</span> <span class="nt">--global</span> dotnet-reqube
</code></pre></div></div>

<p>and do the conversion:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>dotnet-reqube <span class="nt">-i</span> ReSharperReport.xml <span class="nt">-o</span> SonarQubeReport.json <span class="nt">-d</span> YouSolutionDirectory
</code></pre></div></div>

<p>Then, you need to run <a href="https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+MSBuild">Sonar Scanner</a> as usual but with the additional parameter <code class="language-plaintext highlighter-rouge">/d:sonar.externalIssuesReportPaths=SonarQubeReport.json</code> where JSON file is the <code class="language-plaintext highlighter-rouge">-o</code> parameter that you pass to <code class="language-plaintext highlighter-rouge">dotnet-reqube</code>.</p>

<p>That’s it after the analysis is complete, you can see issues detected by ReSharper in SonarQube interface.</p>

<p><img src="/images/2018-06-21/resharper-issues.png" alt="R# issues" class="align-center" /></p>

<p>ReSharper issues will be marked with <code class="language-plaintext highlighter-rouge">R#</code> label.</p>

<p>Please note that external issues have some limitations:</p>

<blockquote>
  <ul>
    <li>they cannot be managed within SonarQube; for instance, there is no ability to mark them False Positive.</li>
    <li>the activation of the rules that raise these issues cannot be managed within SonarQube. In fact, external rules are not visible in the Rules page or reflected in any Quality Profile.</li>
  </ul>
</blockquote>

<p>I’ve created <a href="https://github.com/olsh/resharper-to-sonarqube-example">the example project</a> with a <a href="https://github.com/olsh/resharper-to-sonarqube-example/blob/master/build.cake">Cake script</a> which do all these steps automatically.</p>

<p>If you have any problems with the integration, please open an issue on <a href="https://github.com/olsh/resharper-to-sonarqube-example/issues">GitHub</a>.</p>]]></content><author><name></name></author><category term="resharper" /><category term="sonarqube" /><summary type="html"><![CDATA[Update 2019-08-04 If you are on self-hosted SonarQube server, you can consider using the plugin]]></summary></entry></feed>