Friday, December 25, 2020

MVC Bootstrap dropdown menu and up down symbols

MVC  Bootstrap has a super easy way to create dropdown menus and add up/down symbols on these menus. Basically we just need to include this style in the css file.


/* Style to reverse the caret icon from pointing downwards to upwards */

.dropdown.open .dropdown-toggle .caret {

    border-top-width: 0;

    border-bottom: 4px solid;

}


Please see a fiddle in action at https://jsfiddle.net/pranavnk/o3z7yxf8/4/


reference: https://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_ref_js_dropdown_icon&stacked=h


Friday, October 9, 2020

Encrypt connection strings

 This guide shows how to encrypt whole connection string in web.config in an IIS website.

https://blog.elmah.io/the-ultimate-guide-to-connection-strings-in-web-config/


In short, run this command inside command prompt as administrator

aspnet_regiis -pef "connectionStrings" "c:\path\to\the\folder\containing\webconfig"

Friday, September 11, 2020

iOS build X Code versions and supported sdks

 The page below lists different X Code versions and corresponding SDKs. This information is necessary when using X Code build task in DevOps

https://github.com/actions/virtual-environments/blob/main/images/macos/macos-10.15-Readme.md

Sign Android apps using upload_cert.der from Google Play Console

To publish an android app on production track, it needs to be signed with the right key. Google can automatically manage signing key in the play console for. But we also need to import the key used by google in our local keystore where android studio is generating the apk file.

http://tigar.nl/2018/05/15/android-app-signing/

 

Sunday, August 16, 2020

Async multipart image upload: method not found error

In a strange issue, we would get an error while trying to upload an image using multipart async methods in web api.

  • ExceptionMessage: "Method not found: 'System.Collections.ObjectModel.Collection`1<System.Net.Http.HttpContent> System.Net.Http.MultipartStreamProvider.get_Contents()'."
  • ExceptionType: "System.MissingMethodException"
  • Message: "An error has occurred."
  • Finally we found out that the problem was with System.Net.Http.dll versions not working correctly, the problem and solutions are mentioned at 

    https://stackoverflow.com/questions/54205285/why-im-getting-a-method-not-found-exception-into-production-iis-but-not-in-my-vs

    It was resolved after we added this entry to web.config file

    <configuration>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
    </configuration>

    Monday, August 10, 2020

    Handling website maintenance in IIS


     Before initial go-live or during maintenance of a website, we would like the website to not be visible to outside users, but at the same time it should be accessible to internal users for verifying deployments etc.

    This can be elegantly handled for users using a custom page displaying the message 'website is temporarily down'. In IIS, there is a feature which makes this task much easier. We can simply create an 'App_offline.htm' page and that will display the custom message for all routes. More information can be found at 

    https://activedirectoryfaq.com/2015/01/iis-maintenance-page-app_offline-htm/

    https://docs.microsoft.com/en-us/aspnet/web-forms/overview/deployment/advanced-enterprise-web-deployment/taking-web-applications-offline-with-web-deploy


    However for search engines and other bots, it helps if we return a '503 Service Unavailable' message. More general information about a correct (and elegant) way to handle maintenance mode can be found at https://moz.com/blog/how-to-handle-downtime-during-site-maintenance

    In my case I wanted to:

    1. Show '503 Service Unavailable' message to search engines / bots
    2. Add retry after header
    3. Display 'Site is temporarily available' message to outside users
    4. Make the site accessible to internal users
    To achieve all of the above in an IIS website, web.config file can be modified like so:

    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="Site Unavailable" stopProcessing="true">
                        <match url=".*" />
    <conditions>
                            <add input="{REMOTE_ADDR}" pattern="192\.168\.1\.[0-9]{1,3}" negate="true" />
                         </conditions>
                        <action type="CustomResponse" statusCode="503" subStatusCode="0" statusReason="Site Unavailable" statusDescription="Down for maintenance" />
                    </rule>
                </rules>
            </rewrite>
            <httpErrors errorMode="Custom">
                <error statusCode="503" path="503.htm" responseMode="File" />
            </httpErrors>
        </system.webServer>
    </configuration>

    and a custom 503.htm page can be added to the site:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Maintenance in progress...</title>
    <link href='http://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'>
    <style type="text/css">
    <!--
    .center {
    width: 715px;
    padding-top: 80px;
    margin-left: auto;
    margin-right: auto;
    }
    .offline {
    font-family: "Lato", Arial, Helvetica, sans-serif;
    font-size: 24px;
    }
    .signoff {
    font-size: 14px;
    }
    -->
    </style>
    </head>
     
    <body>
    <div class="offline center">
    <p>Our website is currently undergoing maintenance.</p>
    <p>We are working quickly behind the scenes and the site will be available again very shortly.</p>
    <p class="signoff">Thank you for your patience.</p>
    </div>
    </body>
    </html>







    c# httpclient The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch

     If we get this error while trying to get http reponse using HttpClient object, it could mean that certificate validation fails for the remo...