Developing an ASP.NET Core project on Ubuntu

It's a long time that I'm trying to migrate from Windows/.Net to Linux. But job market have more demands on .Net other than none Microsoft technologies. My hope was on ASP.NET Core. It was not very good at the Beta/RC time but now that is published in final version, my mind has been changed. It now works good on Ubuntu.


At start I created several test projects with ASP.NET Core on both Windows and Ubuntu. I wanted to be sure that ASP.NET Core is capable enough to rely on it in a real world project. I tried to test all aspects of MVC, Web API, Razor, Nuget packages, EF Core, Identity Core, internal DI/IoC, project.json, SQLite, unit testing and tooling include Visual Studio Code, debugging, unit testing, auto complete, code formatting, shortcuts, etc. I tested them on a Windows machine and on an Ubuntu machine with both Unity and Xfce desktops. All tests showed that I will not encounter a big problem utilizing ASP.NET Core itself as first place and using it in Ubuntu at second place.


Using .Net Core in Ubuntu is as same as Windows except that you rely more on terminal than GUI. Using dotnet commands are exactly same in both Windows and Ubuntu. Same names, same switches, same operations and same outputs. It was really good thing that they are exactly same. But when it comes to tooling it is different. While your IDE in both platforms is Visual Studio Code they do not differ very much but if you are used to use Visual Studio 2015 then you can understand how deep is difference between Visual Studio Code and Visual Studio 2015. The latter have a full integration and do everything you need with just pressing some shortcuts. But Visual Studio Code needs many configurations to behave like Visual Studio 2015. Debugging in Visual Studio Code is not as easy as Visual Studio 2015, you need some level skill of operating system to be able to debug codes in Visual Studio Code. My good friend from Visual Studio 2015, IntelliSense, was not working at all at first days. Now that it works, it does not work as good as in Visual Studio 2015. It shows many un-related items too. BTW having Visual Studio Code in Ubuntu is like a miracle. It is very similar to Visual Studio 2015, it has code highlighting, similar shortcuts (Unity desktop), good integration with git, real time compile (to show errors in the code), etc. Did I mentioned that you can use yeoman as a substitution of Visual Studio 2015 templating system that is absent in Visual Studio Code?


The project I am working on it in Ubuntu is a regular web application with parts rendered via MVC and parts delivered to a mobile app as Web API. In development environment I use SQLite as database backend but for production we will be using MS-SQL Server. EF Core works good despite its constraints in verison 1. SQLite in other part also works good as development environment database. It does not allow complete support of EF migration but instead works same from Ubuntu and from Windows. One thing that works great is that the code I'm working on is working exactly same in Windows and Ubuntu. I change code in my Ubuntu machine, commit and push them to the server then pull it from a Windows machine and then continue my development from my Windows machine, no matter I have switched from one OS to another OS. Code behaves same in both OSes and runs exactly same. Additionally code can be developed and run in both Visual Studio Code and Visual Studio 2015 as same. The only consideration is directory structure be designed compatible with structure that Visual Studio 2015 knows about.


I haven't yet deployed the project into a Linux machine as our client probably prefer to use Windows for it. But I hope hosting would not be a problem too. As a long term .Net developer I am very exited about cross platform feature that Microsoft has been added to .Net but frankly I'm a bit worry about it. I'm not sure if Microsoft would continue this way on Linux or not. I am afraid that developers using .Net in Linux would not be as big as Microsoft imagines then abandon it.


I started developing ASP.NET Core on Ubuntu on Unity (standard desktop with Ubuntu). Everything was good except high CPU usage. This problem was not caused by ASP.NET Core instead it was caused by 'hud service' from Unity. For this reason I decided to try Xfce also. It is a light desktop that does not have hud service high CPU usage problem but have problems of its own kind. First thing you encounter is that shortcuts are very very different than Unity. I lost even my Ctrl+F3 (for searching keywords in Visual Studio Code). In rare situations it has problems with high CPU usage of Visual Studio Code (OmniSharp) but bigger problem is regular crashes of my applications like Toggl, my favorite time tracker, and even Google chrome. Though I'm still using Xfce but think I would soon switch back to Unity and find another solution for hud service high CPU usage.


Please see some pictures of my experiences:

asp-net-core-debug-ubuntu-xfce omni-sharp-high-cpu-usage xfce-chrome-crashes


Modifying decade-old ASP.NET application

If you are planning to maintain an application for more than a decade then be careful.

I'm in middle of a case of modifying an ASP.NET WebForm application back to 2006 so 10 years old from now. This application is live for now and it is running for no problem. One month ago we migrated its hosting from Windows Server 2003 to Windows Server 2012 R2 successfully. I can imagine if no modification is needed it would be live for another more decade despite vast changing world of web development and .Net.

But our current problem is different than relocating it from a 2003 windows to a 2012 one. We want to modify it so change or add behaviors to it. Some modifications are easy to apply. For example if an HTML/CSS change is wanted it can be done by modifying ASPX/ASCX files easily. But modifications in code behind ASPX.CS and ASCX.CS file are not easy. Because our application is compiled and no CS file exists in hosting IIS. So changes must be applied in source code then published and converted to DLL files then deployed on the hosting IIS. Our application has dependencies to other assemblies like AjaxControlToolkit 2006 and we have not exact version of them currently. So our application simply wont build and wont publish easily.

At first glance I thought the only choice that we have is to upgrade all dependencies to current version that is impossible. From ten years ago til now many of third party libraries have been discontinued or have many breaking changes. Even ASP.NET itself has been changed very much. Fortunately I got a good solution. That was simple and trivial but I didn't noticed it before. We had published version of the application that means we currently have needed assemblies that are referenced from application. No matters if they are very old or we have not access to their source code. They are valid and executable .Net assemblies that can be referenced from any .Net application.

Iranian developers seeking clients and job positions globally and the sanctions

Time to time I see people get surprised when I tell them Iranian software developers have not access to international job market and can not have global clients easily.

It's a long time that Iran is under US and international sanctions due to political issues. As a result foreign employers especially US based companies are not legally allowed to employ Iranian developers because paying them and having business relations is forbidden.

Some web sites like (An online market for HTML themes and other materials) does not allow browsing their websites inside Iran. They explicitly stated that their site is not available in countries like Iran.


Some other marketplaces does not have Iran in their registration forms fields. You are forced to select another country instead of Iran. An example is


Some other websites have no problem until payments. They need a copy of Passport or a proof of address that obviously would cause problems if you are from Iran. Another problems raises when you want to use PayPal to transfer money. PayPal is based in US.

One of my friend that was working in a freelancing website told me that he had trouble transferring money to Iran. He used a bureau de change via Dubai, UAE to transfer his own money to Iran. A noticeable commission applied to this transfer.

One another friend that wanted to be employed as a remote member of western software development company said everything went OK with the interview. They were satisfied with his skills but when they realized he is Iranian, process stopped.

There also problems getting service from none job websites like Google Developers (formerly Google Code) or Oracle. They do not allow Iranians to use their services.


developersUnfortunately some web sites are censored from inside Iran by government. Twitter is a sample.



EF Migration History not working

In our team we have developers working on same base code that uses EF Code First. All base codes are connected to same database and automatic migration is enabled. Time by time we get errors while running the application. Because some developer may be in past or forward in Model histories. In the other hand developer A may have been added Field AA to table T and developer B may have been added Field BB to table T. This may cause automatic migration to get in trouble. With some errors like table “ABC” exists before.


Today we get a similar error titled:

There is already an object named 'AspNetRoles' in the database.


My first guess was that is is caused by simultaneous but incompatible changes by developers. So checked source control history to see if anything strange has been happened or not. Found nothing unusual. As I had no clue I tried to understand values stored in __MigrationHistory table. It seemed that filed Model is data related to application model changes. It is a long data stored as binary. Googling showed me that my guess is true. I found a good article about it. It showed how to decode this data and extract human readable information from it. That was interesting. This data is in EDMX xml format. Yes EF Code First uses EDMX too but just hides it from scenes. BTW nothing in EDMX was unusual too.


I noticed that format of data in __MigrationHistory has been changed. All digits have been converted to Unicode Persian digits. Consequently I recalled that a colleague had run a T-SQL script on the database so all Arabic characters be converted to Persian characters. This is necessary specially when regarding Persian YEH and KEH characters. We rolled back this process in table __MigrationHistory and run the application once again. It worked again and there is no sign of EF migration problems. All the problem was caused by modifications in the __MigrationHistory table.

Entire family goes Ubuntu

We have a dual boot PC in our home. It has Ubuntu 15.10 and Windows 10 on it. My occasional usage of this PC is done with Ubuntu. Our 5 years old son uses Ubuntu to play online games, watch movies and listen to music. I guess when he go to school we may be forced to use Windows because many educational software forced by schools run only in Windows. But this is for 2 or 3 years later and no fear yet.


Our main reason to still have Windows on our home PC is needs of my wife. She is getting her master degree from university. Needs to prepare documents for her professors so must use same office suite even with same version and same series of fonts with them, otherwise they will not accept the work. As MS Office is widely adopted in Iran, almost all hear classmates also use MS Word and MS Excel file formats to share with them. Tragedy does not ends here. Her university portal just work with specific versions of Internet Explorer. If she want to track her student information from that portal, she must use Internet Explorer. Their university e-learning program runs on Chrome after installing some stuff from Adobe, didn't try it on Ubuntu but it may not work correctly on Ubuntu too.


Windows in not legally sold in Iran and almost all installations are cracked versions. So we love to switch completely to Ubuntu. It also need lower hardware requirements. Now what we can do to switch to Ubuntu and not using Windows? Can we wait under graduation of my wife and hoping my future school of my son does not force to use Windows only educational software?


Honestly I have no definite solution. My wife is no tech savvy and is not very comfortable switch form Windows and MS Office to Ubuntu and LibreOffice. She occasionally searches the web and produces documents based on this searches.


But something has happened and is changing the stations. During last few months I released our home ADSL internet volume is consumed very fast. A 5GB limit is reached during a couple of days while in past this was lasted for couple of weeks. I started thinking what causes this. We have 3 android devices in the home. All automatic updates were on. Changed status of auto update of all to off. Checked 2 Ubuntu devices, home PC and my laptop. They were in ask before mode. All of this made situation better but still one place remained to get inspected. You guessed correct, this was Windows 10 on home PC. I checked its auto-update settings. Surprisingly find out that there is no settings for that. I was unable to make it off. Searching the internet showed that Windows 10 Home edition does not allow disabling automatic update. The only work-around is making network connection as metered so Windows does not use it for getting updates. This work-around does not work for me because our home PC is connected through Ethernet not Wi-Fi and making an Ethernet port as metered is not possible.


As we are not going to get unlimited ADSL internet account for out home, we tried to make a hard decision. Yes we decided to move all remaining activities from Windows to Ubuntu at least for a while. I hope she can read and basic modify of MS Word file in Ubuntu/LibreOffice. Hopefully she can get friendship relationship with Ubuntu, LibreOffice, Firefox and VLC media player. This morning I created a user account in Ubuntu for her. Take time to teach her how to see her emails, how to create LibreOffice Writer documents and how to add Persian characters into it. Recently I have made home PC to a media sharing machine so our son can play movies via his Android tablet device. If no bad problem occurs all of this may lead us to have a Windows free home.

ASP.NET WebForm 2.0 work in Windows Server 2012 R2 again

There is a medium web application in the company that is in use since 2006 to now (2016). This web application is developed with ASP.NET Webform and .Net 2.0 in days of AjaxControlToolkit. For those unfamiliar with that, AjaxControlToolkit and UpdatePanel was an easy way for ASP.NET developers to make use Ajax, the hot technology of the day, in their web applications. Our company web application is hosted in a MS Windows 2003 and now must be hosted to a recent Windows version happened to be MS Windows 2012 R2. This story is about how we manage the application work again in new environment.

The application files copied to a folder in inetpub\wwwroot then an application created for it in IIS. Application was not working with .Net 2.0 App pool because of error “HTTP Error 404.17 – Not Found”. We decided to make it work with a .Net 4.0 App pool. The first error dumped was easy to handle. ASP.Net 4 has some entries of old web.config files into itself so was throwing error duplicate entries. This problem solved by removing those entries from web.config. After it the application get up correctly.

After some usage of the application we explored that some internal tabs are not opening after clicking. Guessing started here. The first guess was that IIS is not serving some file like a .js or a .css file correctly. It was no true because IIS logs and browser profilers did not record any relevant 404 error. Second guess was that something is wrong with AjaxControlToolkit. Our guess was that panels are changed with help of AjaxControlToolkit and UpdatePanel. I checked with Chrome's developer tool. No related console error existed. In another try I changed versions of System.Web.Extensions and AjaxControlToolkit to but didn't helped. Next time added assemblyBinding to web.config but this does not helped too. Event logs of Windows showed no suspicious item too. Several searches in Google neither helped too.

Being hopeless decided to debug client side code of the application in the Chrome developer tool despite of its 4.5K lines of code of legacy ASP.NET WebForm 2.0 application. Started my work by examining JavaScript function that was called by tab headers. javascript:__ShowTAB('ctl00_ContentPlaceHolder1_Panel3',3) was one of those functions. Tracing function calls showed that in an “if comparison” client Ids are not equal. I found it! Client Id generating was changed from .Net 2.0 to .Net 4.0. New one was shorter and didn't had prefix “ctl00_” in beginning of it. A StackOverflow question had same problem. A 2010 post of Scott Gu was showing the complete cause of the problem. ASP.NET 4 WebForm has been moved along a way to generate a cleaner client id. This behavior could be controlled via ClientIDMode. Unfortunately default value of this property was not AutoID while ASP.NET 2.0 behavior was as same as AutoID. I added ClientIDMode = AutoID to the directive of the master page and the problem solved peacefully.

Data history tracking

One of common features in information systems especially in enterprise systems and in systems that has important auditing is history tracking. System operators want to know each data change in the system is done by who in what time. This is true in financial and health information systems.



Different software use different approaches. Web content editing software like Wikipedia and WordPress use versioning mechanism while editing content of an entry. They keep every changes made to an item. So all modifications during several years exists and can be reverted to. This approach usually is good when one or two database tables are tracked this way. Also one or two fields of them are tracked. Otherwise database volume growth will be very huge after a while. Old day developer used to use WORM storage medias so forced to use versioning approach by nature. They were not able to change saved records, instead inserted new records with increased version number.


Full History

Some software solutions use full history strategy. They blindly log every record change automatically. For example consider you modify and Order info and its OrderItems. This translates to multiple record update in database level. A History table will be populated with same count of records indicating old value and current value of modified records (serialized value of all the row), time and person who triggered the change. Utilizing this approach helps finding every tiny information change but also will create large amounts of redundant data that large percent of them will never be used. It's triggering nature may cause cycling problem in addition to performance overhead. Event sourcing technique can reduce performance and storage usage footprints of full history approach.


Process Level Log

Referential integrity, performance overhead, redundancy and data storage waste are obvious weaknesses of versioning and full history approaches. There is another approach that can not be automated like them and does not have high level of accuracy but instead does not suffer from mentioned weaknesses. This approach is done via manual call of logging utility in each high level entry of the system. Process refer to use case scenarios of system usage in the view of end user. Each process begins in high level entries of the system. Developer will fill a brief description of data change, purpose of it and the user or system that triggered it. It can include some detailed information of record changes for advanced auditing usages. A sample class diagram would be like following.


Custom authentication in Asp.Net Core

ASP.NET Core does not have built-in membership for Active Directory. Developers can use Azure Active Directory or external membership services like Facebook and Linkedin or standard ASP.NET Identity mechanism, but are not able to use Active Directory directly. Visual Studio 2015 has removed Active Directory authentication from its web application template:



ASP.NET Core does not have web.config so old school ActiveDirectoryMembershipProvider does not help. ASP.NET Core use middleware mecahnism for handling requests. Settings cookies and checking it back in the server has been changed.


In order to do authentication in ASP.NET Core with Active Directory or any other resource like your own database back end you can take a look at following code.

app.UseCookieAuthentication(options =>


options.AuthenticationScheme = "MyCookieMiddlewareInstance";

options.LoginPath = new PathString("/Account/Unauthorized/");

options.AccessDeniedPath = new PathString("/Account/Forbidden/");

options.AutomaticAuthenticate = true;

options.AutomaticChallenge = true;



This code must be put in Configure method of Startup class of the project. This tells application to use cookie for authentication. Every information is put in cookie, attached to response and sent back to the user. User attaches this cookie to all his/her requests and sent to the server again. This cookie is encrypted and contains Username, Role and other claims added by server code.


var principal =

new ClaimsPrincipal(new ClaimsIdentity(new Claim[] {

new Claim(ClaimTypes.Name, "John"),

new Claim(ClaimTypes.Role, "Administrator")},


await HttpContext.Authentication.SignInAsync("MyCookieMiddlewareInstance", principal);


This code in used in sign in page. This is the place that you validate user entered credentials against a database or resource like Active Directory. For more information see here and here. Also I found a library for the whole process but was not successful to use it.

How Iranians look as software outsourcing contractors?

A good conversation between Dave Hecker from SourceSeek and Vasili Yavorchuk CEO of an outsourcing company from Belarus shows interesting factors that are important for customers and vendors of software outsourcing. Customers tend to divide outsourcing companies by their country. Then try to predicate their behavior by noticing their country. In this conversation we see that American customers loves to see outputs soon but Belarusian developers tend to be more patient. For more info see original blog post here.


I wonder how a typical outsourcing Iranian company would appear for international customers. How customers will encounter while working with an Iranian company. During sanctions and long periods of isolation currently there are few software outsourcing companies in Iran but there are hopes that this will increase soon as world need more affordable prices and higher quality software.


First thing first Iran is well known for the world because it is placed in Middle East and because it is always in the news because of its political issues and nuclear crisis. IT and computer is in first ranks of student population in Iran universities. So many computer/IT graduated can be found in Iran. Iran has copyright law but this is not considered seriously so Iranian software companies are mostly focused on custom software development not product development. Another bad result of not having copyright law is everybody can buy MS Windows, Visual Studio and MS SQL Server for less than 10 USD. As proprietary software is almost free, people and developers does not consider Linux and open source very much.


Computers, smart phones and tablets are widely accessible in all over cities in Iran, in homes, work places, universities and all other places. This is also true for Internet access. Internet in Iran is slow and expensive but exists in everywhere via ADSL, GPRS, 3G, Wimax, etc. Enterprise software development have good market in Iran. Because government agencies and banks are large customers of IT companies. Consequently many developers in Iran have good knowledge in Java and Microsoft .Net. Along them PHP is widely used. Iranian developers love to work with foreign customers but English language may be a problem for them.


Despite all negative points, Iran could be a nice software outsourcing target for international customers as huge amount of developers lives in the country and among them very good developers could be found. Developers in Iran are more satisfied with their jobs than developers anywhere else according to 2015 survey by

One year with Ubuntu

One year ago in a day similar to today I installed Ubuntu on my machine and started evaluating it. I did it not because MS Windows is a bad OS but because it is not available in the country due to political clashes and also because people tends to use cracked versions due to cultural problems. In the other side Ubuntu is not a very common OS but instead is totally free and legal.

I could not able to migrate my development tasks from Windows to Ubuntu because I'm a long term .Net developer. Also many of my clients/employers only want Windows. Instead I managed to switch to Ubuntu in my other daily tasks very quickly. LibreOffice replaced MS Office very easily. Internet browsing could be done in Ubuntu very easily too.

During the year I did my best to migrate all my tasks to Ubuntu. I found many alternatives for my previous Windows based applications like OrchardCMS and others. Also tried hard to bring APS.NET running in Ubuntu or learn Linux friendly software development platforms.


Today LibreOffice works perfectly for all my office requirements. Firefox, Chrome and Thunderbird for Ubuntu help me using Web and Email very perfectly. Gimp helps me editing images very good. I even had experiences with Inkscape for vector graphics. Integration with Windows is not bad. I can remote desktop to Windows machines just from my Ubuntu machine. Ubuntu can read FAT32/NTFS partitions good. All my previous MS Office files could be read and edited by LibreOffice too. Also my 4 years old child could use Ubuntu to access online games, play videos and music and even run games and educational applications like GCompris.

I learned many command line tools and terminal during the year. I even have an operational Ubuntu VPS live on Internet that is running WordPress, RedMine and Vtiger CRM very nicely. I do all maintenance tasks of server via terminal and it is joyful.

I have tried establishing software development environments on Ubuntu. Rails, Node.js and Java have been setup successfully. Even I was able to develop simple introductory applications with help of them and Sublime Text. It was a good experience but I still have doubts about choosing which of them to continue.