Sunday, 21 June 2020

Optimizing your Asp.net Application development

Things to consider while developing Asp.net application
  • Use T4MVC tool 
  • Use Mini profiler for performance tracking (https://miniprofiler.com/)
  • Use Log4net or equivalent logging tool
  • Do not store log4net logs on deployment server, redirect them to loggly or logstash hosted on another server
  • Do not use hard coded string for error, information, success messages (view or code behind)
    • Later if client asks for localization these hard coded strings makes it difficult to localize your application
    • Use resource files even though right now there is no requirement for localization
  • Use Tiny Mapper (Map thousands of objects in jiffy) http://tinymapper.net/

Localization in asp.net 4.7

Recently I came across a task, to provide Spanish version of a page. The website which needs this change is designed in asp.net 4.7.

After working many years in asp.net I knew asp.net has localization feature which is pretty easy to implement. But I never got chance to work on it.

I thought of writing this post so that if in future I forgot how to do it I can use it. Also it is help to someone who is trying to achieve similar goal for first time.

Prerequisite:

You have your asp.net MVC 4.5+ website application. If you don't have it, create a new application using visual studio template. Use visual studio 2017 or 2019.

Steps:
  • Add a new folder, give it any meaningful name. For my convenience I will name it as "Localization". It is not mandatory to create a new folder.
  • Right click on newly created folder, click on 'add new item'. Select Resource file. Give it meaningful name. I am giving it name as "Resource.resx"

  • Resource file is XML file having key value pair. This file will contain all label and text messages in English language. 

  • Similarly you need to create a new resource file for Spanish version. You have to name this file as Resource.es.resx. Note  file name format is important here <filename>.<locale-code>.resx
  • Set culture locale in view or code behind file. 
  • I am passing language / Locale using query string. Again this is not mandatory. You can set locale using cookie, session or any other technique.



    Search This Blog

    Creating your first "Alexa" Skill

    Index What is Alexa What is Alexa Skill? Why is it required when Alexa already equipped with voice assistant? Dev...