Dec 22, 2015

RePost - ELMAH

Check this out :

https://code.google.com/p/elmah/

Oct 16, 2015

ASP.NET MVC routing ordering

Always place more specific route before less specific in your routes definitions ....
And I always forget it.
More specific route includes your parameters and so :
        
    routes.MapRoute("ReportsWithoutMISCode",
              "Reports/{Action}/{programObjectiveId}/{userName}",
              new { controller = "Reports", action = "Index" },
              new { programObjectiveId = @"\d+" },
              new[] { "Web.Controllers.Reports" });
     routes.MapRoute("ReportsWithMISCode",
              "Reports/{Action}/{programObjectiveId}/{userName}/{MISCode}",
              new { controller = "Reports", action = "Index" },
              new { programObjectiveId = @"\d+" },
              new[] { "Web.Controllers.Reports" });

; should be switched since second route ReportsWithMISCode is more specific, means having more parameters.

So it should be:

     routes.MapRoute("ReportsWithMISCode",
              "Reports/{Action}/{programObjectiveId}/{userName}/{MISCode}",
              new { controller = "Reports", action = "Index" },
              new { programObjectiveId = @"\d+" },
              new[] { "Web.Controllers.Reports" });
      routes.MapRoute("ReportsWithoutMISCode",
              "Reports/{Action}/{programObjectiveId}/{userName}",
              new { controller = "Reports", action = "Index" },
              new { programObjectiveId = @"\d+" },
              new[] { "Web.Controllers.Reports" });

It is interesting to note that in first case route works in awkward way. It gets matched but third parameter MISCode is appended as query param with question mark like this:

...ReportXXX/101/pt2?MISCode=MyMISCode

After switching to second solution we get friendly url.

Aug 19, 2015

Regex - Match only first occurence

In UTF-8 HTML text like this :

<table>
<tr class="dummy">
First
</tr>
<tr class="foo">
Second
</tr>
</table>
; you want to parse out list of two rows.

First,
Second

To achieve this use non greedy expression ?. Basically after you state what is pattern and how often it occurs by using ? you want to limit search only to first occurence.

Example regex with UTF8 greedy expression:

(?<=tr\sclass="\w+">)+?(?>\P{M}\p{M}*)+?(?:\<\/tr\>)+?
http://stackoverflow.com/questions/2503413/regular-expression-to-stop-at-first-match