Through this blog, it is my effort to share experiences with the community and make the journey enjoyable.

Wednesday, November 18, 2015

Multi Tenancy Identifier for Office 365

When creating Multi Tenancy environment, there is always a identify the Tenant Id, so that corresponding data could be stored and fetched from Datasource.

In TokenHelper.cs there is a public method GetRealmFromTargetUrl(Uri targetApplicationUri) that takes URI of the target sharepoint site as its parameter. This method actually return a string representation of the realm GUID

Realm is unique to each tenant in Office 365 or to each SharePoint farm on-premises. It is possible to discover the realm at run time. So, it is not necessary to cache this information between requests, but it will cost you an extra round trip to SharePoint each time you want to look it up. If you use code similar toTokenHelper.GetRealmFromTargetUrl with the site URL, and cache the result per site (or even per site and per user), you can use this later without making the extra call.

var tenantAdminUri = new Uri(String.Format("https://{0}", tenantStr));

string realm = TokenHelper.GetRealmFromTargetUrl(tenantAdminUri);

You can use Guid now to identify the Tenant.

Location: India Indore, Madhya Pradesh, India


Post a Comment

Search This Blog


The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway. All posts are provided "AS IS" with no warranties, and confers no rights. In addition, my thoughts and opinions often change, and as a weblog is intended to provide a semi-permanent point in time snapshot you should not consider out of date posts to reflect my current thoughts and opinions.

Popular Posts

Total Pageviews