Monday, 7 October 2013

Deploy code first DB based web app to Windows Azure

If you created a ASP.NET MVC4 app using EF5 code first model, and you want to deploy the app onto Windows Azure, basically there are 2 steps you need to follow:

migrations folderFirst, enable code first migration so server side knows how to re-create the database. You can achieve this in Package Management Console by executing “enable-migrations”. If succeeded you will see a new folder name Migrations created in the project file root (see screenshot), click here for more details of code first migrations.

Then create a web site on Azure server and remember to create a database at the same time by following the online guide. Once website created you can get the publish profile which contains the database connection string so later when you use the publish profile to deploy your website those values can be used to replace your LocalDB connection string value (see screenshot below), and remember tick the Execute Code First Migrations option before click Next.publish ui

Tuesday, 27 August 2013

Launch an app from another app: cross platform review

Android platform allows launch any app from inside of other app as long as we know the full package name of the target app. Developer can even specify the activity to be opened initially.

iOS and Windows Phone don’t allow launch arbitrary app on the device, instead, they have different approach, the URL scheme. The targe app can register a specific URL scheme (for example “com.facebook:” for Facebook app), later when user launches the same URL from either another app or inside a webpage the target app will be launched automatically. Developer can also pass parameters in the URL just like we do in a normal URL.

Please be aware, the URL scheme introduces a security flaw because any third party app can register the same URL scheme. If more than one third-party app registers to handle the same URL scheme: for iOS, there is currently no process for determining which app will be given that scheme (see doc); for Windows Phone, each time the user opens the file, they will be asked which app they want to use.

Besides, Windows Phone provides a way that launching apps from the same publisher who published the current app. See below the code sample:

IEnumerable<Package> apps = Windows.Phone.Management.Deployment
                                                    .InstallationManager
                                                    .FindPackagesForCurrentPublisher();
apps.First().Launch(string.Empty);

Wednesday, 10 July 2013

HttpWebRequest Connection limitation


As you may know, by default, the System.Net implementation of C# is using connection pool to improving performance which respects restrictions stated in http 1.1 - one user agent SHOULD NOT create more than 2 connection to a server. This causes max 2 live connections can be created by HttpWebRequest in the same app domain at any time. So the wordaround can be just host the code in different app domains and fire the method in multi threads.

Or, you can change app configuration to rewrite the default connection limit:
<system.net>
     <connectionManagement>
         <add address="*" maxcoonection="2000" />
     </connectionManagement>
</system.net>

Or, you can rewrite the limitation in your code before initialize the first HttpWebRequest:
ServicePointManager.DefaultConnectionLimit = 100;