Wednesday, June 21, 2017

IIS problems

Some commands to help troubleshoot windows hosted web applications 

URL reservations: 

netsh http show urlacl
netsh http delete urlacl url=https://+:443/
netsh http add urlacl url=https://+:443/ user=everyone

Firewall

netsh advfirewall firewall add rule name="IISExpressWeb" dir=in protocol=tcp localport=443 remoteip=any action=allow

Certificates

delete cert
netsh http delete sslcert ipport=0.0.0.0:44347

Add cert
netsh http add sslcert ipport=0.0.0.0:44347 certhash=d4e23174e12ec96e8d3b7cacf7a4f83da9c08e12 appid={214124cd-d05b-4309-9af9-9caa44b2b74a}

Network 
netstat -a -n -o | findstr 443
netstat -ab  | findstr 443

Apppool
Look at the app pools status
c:\Windows\System32\inetsrv\appcmd.exe list apppools

Check event viewer

In my case i found the following error
An error occurred while using SSL configuration for endpoint 127.0.0.1:443.  The error status code is contained within the returned data.


Monday, June 12, 2017

Git tips

git config push.default current
Pushing to the server with he same branch name automatically

Some usefull aliases 
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.brb branch -b
git config --global alias.st status
git config --global alias.unstage 'reset HEAD --'

Sunday, June 4, 2017

DateTime parsing in .NET

Good percentage of bugs and test failures comes from the way date is parsed.
Popular example, a unit test is created, runs on local machine without any problems, then on the test agents, sometimes it passes, and other times fails.
Usually this happens when there is a date stored in UTC for example, then we parse it without specifying date kind, which may change the time value in some cases.

Example below for different ways to parse date, and the effect of that on a time comparison.
Whenever the parsed date kind is local, and the time is adjusted, the comparison is not as we expect.
In the below examples, i am comparing the dates checking if less than 8:40 and expecting all to be true. Some of the them the comparison was giving false, due to time adjustment.

namespace DateParsing
{
    using System.Globalization;
    using System.Xml;

    class Program
    {
        static void Main(string[] args)
        {
            Parse("2017-06-01T08:33:49Z");
            Parse("2017-06-01T08:33:49");
            Parse("2017-06-01T08:00:00.0000000Z");
            ParseByFormat("2017-06-01 08:33:49", "yyyy-MM-dd HH:mm:ss");
            Console.ReadKey();
        }

        private static void Parse(string dateString)
        {
            Console.WriteLine("========== input string is: {0} ===============", dateString);
            var date1 = DateTime.Parse(dateString);
            PrintDate(date1, "Using parse, no date style");
            var date2 = DateTime.Parse(dateString, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
            PrintDate(date2, "Using parse, Adjust to universal style");
            var date3 = DateTime.Parse(dateString, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
            PrintDate(date3, "Using parse, Assume universal style");
            var date4 = XmlConvert.ToDateTime(dateString, XmlDateTimeSerializationMode.Utc);
            PrintDate(date4, "Using XmlConvert, SerializationMode UTC");
        }

        private static void ParseByFormat(string dateString, string format)
        {
            Console.WriteLine("========== input string is: {0} ===============", dateString);
            var date1 = DateTime.ParseExact(dateString, format, CultureInfo.InvariantCulture);
            PrintDate(date1, "Using parse exact, no date style");
            var date2 = DateTime.ParseExact(dateString, format, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
            PrintDate(date2, "Using parse exact, Adjust to universal style");
            var date3 = DateTime.ParseExact(dateString, format, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
            PrintDate(date3, "Using parse exact, Assume universal style");
            var date4 = XmlConvert.ToDateTime(dateString, format);
            PrintDate(date4, "Using XmlConvert, SerializationMode not specified");
        }

        static void PrintDate(DateTime date, string format)
        {
            DateTime x = new DateTime(2017, 06, 01, 08, 40, 00);
            Console.WriteLine("Date is {0}, date kind is {1}, {2}", date, date.Kind, format);
            Console.WriteLine("{0} < than {1} is {2} ", date, x, date < x);
        }
    }
}


========== input string is: 2017-06-01T08:33:49Z ===============
Date is 01/06/2017 09:33:49, date kind is Local, Using parse, no date style
01/06/2017 09:33:49 < than 01/06/2017 08:40:00 is False
Date is 01/06/2017 08:33:49, date kind is Utc, Using parse, Adjust to universal style
01/06/2017 08:33:49 < than 01/06/2017 08:40:00 is True
Date is 01/06/2017 09:33:49, date kind is Local, Using parse, Assume universal style
01/06/2017 09:33:49 < than 01/06/2017 08:40:00 is False
Date is 01/06/2017 08:33:49, date kind is Utc, Using XmlConvert, SerializationMode UTC
01/06/2017 08:33:49 < than 01/06/2017 08:40:00 is True

========== input string is: 2017-06-01T08:33:49 ===============
Date is 01/06/2017 08:33:49, date kind is Unspecified, Using parse, no date style
01/06/2017 08:33:49 < than 01/06/2017 08:40:00 is True
Date is 01/06/2017 08:33:49, date kind is Unspecified, Using parse, Adjust to universal style
01/06/2017 08:33:49 < than 01/06/2017 08:40:00 is True
Date is 01/06/2017 09:33:49, date kind is Local, Using parse, Assume universal style
01/06/2017 09:33:49 < than 01/06/2017 08:40:00 is False
Date is 01/06/2017 08:33:49, date kind is Utc, Using XmlConvert, SerializationMode UTC
01/06/2017 08:33:49 < than 01/06/2017 08:40:00 is True

========== input string is: 2017-06-01T08:00:00.0000000Z ===============
Date is 01/06/2017 09:00:00, date kind is Local, Using parse, no date style
01/06/2017 09:00:00 < than 01/06/2017 08:40:00 is False
Date is 01/06/2017 08:00:00, date kind is Utc, Using parse, Adjust to universal style
01/06/2017 08:00:00 < than 01/06/2017 08:40:00 is True
Date is 01/06/2017 09:00:00, date kind is Local, Using parse, Assume universal style
01/06/2017 09:00:00 < than 01/06/2017 08:40:00 is False
Date is 01/06/2017 08:00:00, date kind is Utc, Using XmlConvert, SerializationMode UTC
01/06/2017 08:00:00 < than 01/06/2017 08:40:00 is True

========== input string is: 2017-06-01 08:33:49 ===============
Date is 01/06/2017 08:33:49, date kind is Unspecified, Using parse exact, no date style
01/06/2017 08:33:49 < than 01/06/2017 08:40:00 is True
Date is 01/06/2017 08:33:49, date kind is Unspecified, Using parse exact, Adjust to universal style
01/06/2017 08:33:49 < than 01/06/2017 08:40:00 is True
Date is 01/06/2017 09:33:49, date kind is Local, Using parse exact, Assume universal style
01/06/2017 09:33:49 < than 01/06/2017 08:40:00 is False
Date is 01/06/2017 08:33:49, date kind is Unspecified, Using XmlConvert, SerializationMode not specified
01/06/2017 08:33:49 < than 01/06/2017 08:40:00 is True