Client.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler()) not working when offline

In Xamarin.IOS I found that Azure mobile app in offline mode wouldnt get past this line when offline.

await MobileService.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler())

And if you remove the await and put a Wait at the end that just causes deadlock.

Only solution I found that works is:

System.Threading.Tasks.Task.Run(() => MobileService.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler())).Wait();

This is as per Quickstarts sample so clearly they need to update it.

Create and download a backup from SQL Azure Database Service

Open command prompt and run the below command. In this case you’ll need to create C:\backups folder first.

"C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\SqlPackage.exe" /Action:Export /SourceServerName:"tcp:xxxxx.database.windows.net,1433" /SourceDatabaseName:DbName /SourceUser:user /SourcePassword:password /TargetFile:C:\backups\backup.bacpac

You will need to replace the bits in bold with whatever is relevant for you.

Azure Mobile App – Get username from custom authentication when User.Identity.Name is blank

If you’ve setup custom authentication with Aspnet Identity as mentioned in my previous post or using some other custom authentication and you need to get the authorized users username, the below should do the trick:

ClaimsPrincipal claimsUser = (ClaimsPrincipal)this.User;
            string id = claimsUser.FindFirst(ClaimTypes.NameIdentifier).Value;

I used this to filter my GetAllItems table controller like so:

return Query().Where(todo=> todo.Username == id);

 

Access content as system user – SPSecurity.RunWithElevatedPrivileges

Any code behind in SharePoint defaults to run as the current logged on user on the site. However this can become an issue if you want to programmatically update/access content that the user does not have permission to. For instance on the code behind of a layout page or workflow.

To get around this you need to run the code under ‘elevated privileges‘ following the example below:

 

SPSecurity.RunWithElevatedPrivileges(delegate()

{

using (SPSite site = new SPSite(web.Site.ID))

{

// write your code here

}

});