Preheat oven to 350 F.
If using frozen corn, defrost, and keep it aside.
Heat the olive oil in a skillet or pan on medium heat. Add the onions and sauté until soft and translucent, about 4-5 minutes. Add garlic and green chilies and sauté for a few minutes until the raw smell of the garlic is gone.
Then add the cream cheese and sauté for a few more minutes until it is well blended with the onion-garlic mixture.
Add the ketchup and cilantro and cook on low heat for 1-2 minutes. Finally, add corn and salt and mix well. Set the corn mixture aside.
To prepare the Béchamel sauce, warm up the milk in a microwave for one minute.
Add the butter to a heavy-bottomed pan and melt it on medium heat. Then add the flour to the melted butter and whisk it until it is smooth and starts to bubble, making sure it doesn’t brown. Adjust the temperature to prevent the flour from burning.
Then add the warm milk to the flour and butter mixture. As you pour the milk, keep whisking the flour and milk sauce until it starts bubbling. The whisking also prevents any lumps in the sauce. It takes only a minute for the sauce to thicken. Pour the sauce in the corn mixture and mix well.
Evenly spread 1/3 of the corn mixture in a casserole, and sprinkle 1/3 of the shredded cheese over it. Repeat until you finish the mixture and the cheese.
Bake it in the preheated oven for 20-25 minutes or until the cheese starts bubbling. Serve hot with naan or any fresh bread.