Tag Archives: error

Facebook Access Token Request does not work in IE 8

Integrating Facebook Feeds to your Web Application could be a very common thing nowadays. Supporting this integration across different browser could be a headache for most developers out there. Including me myself.

At the end of this session, you will know how to perform an AJAX request to query Facebook feeds access token at client side which support IE 8 Browsers and all other Modern browsers. Using jQuery 1.9

Note: You can only do client side query if your web servers are not having internet connectivity to Facebook. Especially “graph.facebook.com” where you perform access token retrieval and Graph API.

First of all, you need a jQuery and Facebook JS like this

<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head></pre>
<body>
 <div id="fb-root">
 <script type="text/javascript" src="https://connect.facebook.net/en_US/all.js"></script>
 </div>
...
</body>

And then you need this to initialise FB SDK

<script type="text/javascript">
var access_tokenParam = ""; //to store the access token
var appId = "" // YOUR APP ID HERE
var appSecret = "" //APP SECRET;

window.fbAsyncInit = function () {
 FB.init({
 appId: appId, //App Id
 status: true,
 xfbml: true
 });

};
</script>

Lastly, you need create a Facebook App (if you have not) for an App ID and App Secret key. You can get it here App DashBoard

Note that you need to set your App to use the testing domain URL. In my cases, i use “facebooktest.com”

facebook app dashboard setting

Not to forget to map this URL to your 127.0.0.1 in hosts file (C:\Windows\System32\drivers\etc\hosts)

127.0.0.1 facebooktest.com

To share what happened before i come to a workaround, below are the JavaScript to obtain Facebook access token to perform Graph API. THIS WORKS in all other browser EXCEPT Internet Explore 8.


$.support.cors = true; //

$.ajax({
 type: "POST",
 url: "https://graph.facebook.com/oauth/access_token",
 cache: false,
 data: {
 "client_id": appId,
 "client_secret": appSecret,
 "grant_type": "client_credentials"
 },
 error: function (xhr, status, error) {

//ERROR THROWN TypeError: Access is Denied for IE8
 },
 success: function (response) {

 },
 complete: function (request, textStatus) {
 if (request.responseText != null) {
 access_tokenParam = request.responseText.split('=')[0] + "=" + escape(request.responseText.split('=')[1]);
//access_tokenParam will be the token that you will then be used for subsequently Graph call
 }

}
 });

If this script runs on IE 8, you will hit TypeError: Access is Denied This is due to IE 8 does not use the XMLHttpRequest, but an alternative object named XDomainRequest. Some googling suggested using JSONP. Alright, lets try.

$.ajax({
 type: "POST",
 url: "https://graph.facebook.com/oauth/access_token",
 cache: false,
 dataType: "jsonp",
 data: {
 "client_id": appId,
 "client_secret": appSecret,
 "grant_type": "client_credentials"
 },

error: function (xhr, status, error) {

//ERROR Thrown "Parseerror" in IE8 AGAIN...
 });

The above both attempts to get the access token failed in IE8. After digging deeper to Facebook Documentation, i found this

There is another method to make calls to the Graph API that doesn't require using a generated app token. You can just pass your app id and app secret as the access_token parameter when you make a call:
http://graph.facebook.com/endpoint?key=value&access_token=app_id|app_secret
The choice to use a generated access token vs. this method depends on where you hide your app secret.

Holy cow…

What you need to do is just setting your access token as per below

access_tokenParam = “access_token=XXX|YYY”

where XXX is your App ID and YYY is your App Secret. e.g. “access_token=778487422177917|gu_TZwkQe5jtBj7VvZpMJX8odlx”

don’t try to use it, it is not valid =)

Knowning that the Access Token needs not to be provided by Graph, you may then perform API call like this (taking my posts as example)


access_tokenParam = 'access_token=' + appId + '|' + appSecret;
renderFBNewsFeed('yihaa5', access_tokenParam);

function renderFBNewsFeed(id, access_tokenParam) {
 var url = '/' + id + '/posts?' + access_tokenParam;
 FB.api(url, { return_ssl_resources: 1 }, function (response) {
 if (response.data) {
 var html = "";
 for (var i = 0; i < response.data.length; i++) {
 var obj = response.data[i];
 var fakeTitle = obj.name ? obj.name : (obj.story ? obj.story : obj.message );
 var fakeDes = obj.description? obj.description : obj.caption;
 html += "<h2>" + fakeTitle + "</h2>";
 html += "<h3>" + fakeDes + "</h3>";
 }
 $("#fbNewsWrapper").html(html);
 }
 });

}

You can find the entire html file here Hope it helps!

Change the default settings for newly created SharePoint Document Library

Thought it would be helpful to share this.

As you know, SharePoint Document Library by default, if you just simply create one, are not turned on with Version Control. This could rather prone to human mistake or mis-configuration whenever you need to provision a new document library.

This is how I fulfill this.

Imagine i need to have the version control turn on, and with the following settings

version history limits

What you need to do is to create a custom event receiver with List Added handler

Fire up your Visual Studio, create a SharePoint Farm solution and add your new event receiver

New Event Receiver

Select List Events and tick “A list was added”

Event Receiver Setting

In the ListAdded method, kindly do a checking before the code is firing, the below TemplateId 101 means Document Library


if (properties.List != null && properties.TemplateId == 101 && properties.Web != null)
 {

try
 {
 SPList docList = properties.List;//.Lists[properties.ListId];
 docList.EnableVersioning = true;
 docList.EnableMinorVersions = true;
 docList.MajorVersionLimit = 3;
 docList.MajorWithMinorVersionsLimit = 20;

//this.EventFiringEnabled = false;
 docList.Update();
 }
catch (Exception ex)
 {

//Do something...

}

}

If you do this, you will hit this error when creating a new document library

The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.

This is due to the Synchronisation mode for ListAdded event by default is “Asynchronous”.
You MUST DO the following

Open the Element.xml created via Visual Studio.
Add a “<Synchronization>Synchronous</Synchronization>” node into your receiver xml

<Receiver>
 <Name>SharePointSettingEventReceiverListAdded</Name>
 <Type>ListAdded</Type>
 <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
 <Class>MOT.EventReceiver.SharePointSettingEventReceiver.SharePointSettingEventReceiver</Class>
 <SequenceNumber>10000</SequenceNumber>
 <Synchronization>Synchronous</Synchronization>
 </Receiver>
 </Receivers>

Deploy your solution and hooray~

Exception trying get context compatibility level: System.IO.FileNotFoundException

Bump into this error when hitting my SharePoint 2013 Web Application.

HTTP/1.1 200 OK Server: Microsoft-IIS/7.5 Date: <DATE TIME> GMT Connection: close

Exception trying get context compatibility level: System.IO.FileNotFoundException: The site <URL> could not be found in the Web application SPWebApplication Name=<WEB_APP_NAME>.
 at Microsoft.SharePoint.SPSite.LookupSiteInfo(SPFarm farm, Boolean contextSite, Boolean swapSchemeForPathBasedSites, Uri& requestUri, Boolean& lookupRequiredContext, Guid& applicationId, Guid& contentDatabaseId, Guid& siteId, Guid& siteSubscriptionId, SPUrlZone& zone, String& serverRelativeUrl, Boolean& hostHeaderIsSiteName, Boolean& appWebRequest, String& appHostHeaderRedirectDomain, String& appSiteDomainPrefix, String& subscriptionName, String& appSiteDomainId, Uri& primaryUri)
 at Microsoft.SharePoint.ApplicationRuntime.SPRequestModule.GetContextCompatibilityLevel(Uri requestUri)

Subsequently, i tried to run powershell Get-SPSite <url>

Get-SPSite : Cannot find an SPSite object with Id or Url : xxxx

Tried to go to central admin and view all site collections. Amazingly, there is no Site Collection attached to the Web Application.  The site collection was GONE by no reason…

Steps to Recover the Site Collection

  1. Run the following Powershell.
    $tempSite = Get-SPDeletedSite
    $tempSite.Restore()
  2. That simple…

Internet Explorer IE 10 cannot open SharePoint 2013 Document Library in Windows Explorer

As stated in the post title, this error below thrown after clicking Open with Explorer. This happen only when you are using Internet Explorer 10 in Windows 7 or  Windows Server 2008 R2 as mentioned in MS Support.
We re having a problem opening this location in file explorer

You will need to install this hotfix http://www.microsoft.com/en-us/download/details.aspx?id=39849

Please take note whne you try to push down the client computer requirements for SharePoint 2013 with IE 10 + Windows 7!

 

Distributed Cache Status Down, CacheHostInfo is null

This problem troubled me for like 2 days consecutively while i have to stay in the data center (with the crazily cool air-con) to troubleshoot, its kinda driving me crazy.

I have two (2) SharePoint 2013 app servers to be running Distributed Cache services. Each to be allocated with 8 GB RAM. When i setup one of the Distributed Cache server (running alone), it was fine. The issue came when i tried to start the other SharePoint App server (within the same SharePoint farm) to run the Distributed Cache service, the App Fabric Caching Services stuck at “Starting” status for about 5 mins+  Subsequently, error thrown to System Log file saying the service terminated unexpectedly.

I Followed Technet guide and it doesn’t work.

Tried to “Remove-SPDistributedCacheServiceInstance”, it loaded for a long long time then thrown “net.tcp://<servername>/” times out.

In the Central Admin > Manage Services on server. Selected the Not-working app server. I found the Distributed Cache service is not started. Click on the “Start” link, it threw “Cachehostinfo is null” friendly message…

Tried Get-SPServiceInstance to get the broken distributed cache instance, deleted and rerun “Add-SPDistributedCacheServiceInstance”, it loaded, again for a lon glong time.

Tried

Remove-CacheHost
Add-CacheHost -ProviderType "SPDistributedCacheProvider -ConnectionString "Data Source=<SPSQL ALIAS>;Initial Catalog=Config;Integrated Security=True;Enlist=False"
#####

Still no help.

After checking the window System Log file, i noticed this error was thrown somewhen during the process.

Event ID 4
####
The kerberos client received a KRB_AP_ERR_MODIFIED error from the server &lt;My Broken Server Name&gt;. 
The target name used was &lt;My Service Account&gt;. This indicates that the password used to encrypt the kerberos 
service ticket is different than that on the target server.
####

Fishy enough.

If you are having this problem, you can consider the following step

My Resolution

  1. Check Network Connection for both your SharePoint servers that are running the Distributed Cache.
  2. Go to the Properties of the connection
  3. Double click “Internet Protocol Version 4 (TCP/IPv4)
  4. Ensure both servers are using SAME and WORKING DNS Servers. Reason why is that my servers were having two Domain Controllers (one for backup replication purposes). For some reason, the DCs cannot talk to each other.
  5. Remove the Alternate DNS Server as for now.
  6. Try to Remove-SPDistributedCacheServiceInstance and Add-SPDistributedCacheServiceInstance for the non-working app server.

Hope it solves your problem =)

WebHost failed to process a request AND SQL database login for Config on instance SQL failed

After setting up my SharePoint 2013 for both Web Front End Server and Application Server. I encountered the following error in my WFE server

Source: System.ServiceModel 4.0.0.0

Task Category: WebHost

Event ID: 3


WebHost failed to process a request.
 Sender Information: System.ServiceModel.ServiceHostingEnvironment+HostingManager/63835064
 Exception: System.ServiceModel.ServiceActivationException: The service '/SecurityTokenServiceApplication/securitytoken.svc' cannot be activated due to an exception during compilation. The exception message is: Exception has been thrown by the target of an invocation.. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: The farm is unavailable.
 at Microsoft.SharePoint.Administration.Claims.SPSecurityTokenServiceManager.get_Local()
 at Microsoft.SharePoint.IdentityModel.SPSecurityTokenServiceConfiguration..ctor()
 --- End of inner exception stack trace ---
 at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
 at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
 at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
 at System.Activator.CreateInstance(Type type, Boolean nonPublic)
 at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
 at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
 at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture)
 at Microsoft.IdentityModel.Protocols.WSTrust.WSTrustServiceHostFactory.CreateSecurityTokenServiceConfiguration(String constructorString)
 at Microsoft.IdentityModel.Protocols.WSTrust.WSTrustServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses)
 at Microsoft.SharePoint.IdentityModel.SPSecurityTokenServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses)
 at System.ServiceModel.ServiceHostingEnvironment.HostingManager.CreateService(String normalizedVirtualPath, EventTraceActivity eventTraceActivity)
 at System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity)
 at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity)
 --- End of inner exception stack trace ---
 at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity)
 at System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(String relativeVirtualPath, EventTraceActivity eventTraceActivity)
 Process Name: w3wp
 Process ID: 4844

TOGETHER with

Source: SharePoint Foundation

Task Category: Database

Event ID: 3351


SQL database login for 'SHAREPOPINT CONFIG DB NAME' on instance 'SQL INSTANCE NAME' failed. Additional error information from SQL Server is included below.

Login failed for user 'Web Front End SERVERNAME$'.

The reason why i mentioned these two events are together is that the resolution below that i did is related to the two error events. If your event log does not contain these two errors, it is likely that the resolution below may not work for you.

Resolution

  1. Go to the server that contain these error message (Web Front Event server).
  2. Open IIS (Internet Information Services) Manager
  3. In the Connections panel, navigate to Application Pools
  4. (In my case, the “SecurityTokenServiceApplicationPool” Application Pool is running using “LocalSystem” account)
  5. Select the SecurityTokenServiceApplicationPool and click “Advanced Settings” from the action panel.
  6. Scroll to ProcessModel section and change the Identity to YOUR SharePoint Farm Account!
  7. Click Ok and Recycle the application pool and done!

SharePoint 2013 Pre-requisite Error – Application Server Role and Web Server (IIS) Role

Bumped into  this error when trying to manually setup SharePoint 2013 pre requisite installation.

The Configuration stopped at step Configuring Application Server Role and Web Server (IIS) Role.

SP2013 Error - Pre-requisite App Server and Web Server

Resolution

  1. Go to Server Manager > Add Roles and Features
  2. Select Your server in the Server Pool under Server Selection page
  3. Select Web Server (IIS) Role
  4. Click Next until the wizard finishes
  5. Rerun the Pre-requisite setup and the error is gone.

SharePoint 2013 – Newsfeed not showing anything.

After successfully setup my User Profile Services + User Profile Synchronisation Services. I then setup “My Site” in which you need to manually create a Managed Path in the Web Application which hosts your My Site.

After setting them up, you shall see “News Feed’, “SkyDrive” and “Sites” appear on the Ribbon Bar. Yes! at least something is showing. I then happily click on the News Feed. The SharePoint is showing a message, We Are working on it. While waiting for the setup, you may edit your profile, contact bla bla bla.. ok. Maybe I should just wait for a while. The next day i came back to the same URL, this message is still showing!

Then i noticed this error in ULS LOG

Unexpected error occurred in method 'GetObject' , usage 'FeedCache' - Exception 'Microsoft.ApplicationServer.Caching.DataCacheException: ErrorCode<ERRCA0018>:SubStatus<ES0001>:The request timed out.. Additional Information : The client was trying to communicate with the server : net.tcp://<<MY-SHAREPOINT-URL>>:22233

Apparently there is something wrong with the Distributed Cache Service.

Resolution

To solve this problem, first thing you have to ensure that the Distributed Cache Service in “Manage Services on Server” is not Stopped. If not Started, please kindly follow this to Add your SharePoint server to existing cache cluster. (You may need to check if you have already setup cache cluster.

To add a server to cache cluster, Do this

Add-SPDistributedCacheServiceInstance

At times, the Distributed Cache service maybe corrupted (for whatever reason), you may Remove the server from cluster and add them back again.

Simply

Remove-SPDistributedCacheServiceInstance

Then

Add-SPDistributedCacheServiceInstance

If this still doesn’t work, please ensure your Windows Firewall is open to ICMPV4 and ICMPV6 Inbound Rules. (Check Here)


					

Unable to connect the Search Services

I’ve already setup the environment correctly base on the Technet guide.

The farm topology is 1 WFE, 1APP (which runs the Search Service Instance), 1 SQL and 1 Fast Search server.

This error happen after few months of system commission.

Whenever hitting a keyword via the Search Box, this error “Unable to connect the search services” kept throwing.

Resolution

After checking the server system time, i noticed that there is 5++ mins difference between APP Server and Fast Search Server. This time difference will cause the web service call to fail!!

Hence, please ensure that your Search Service Instance server and the FAST Search are in synch with the time. I’ve heard that there is this NTP for servers to synch up the time. You may explore it in detail yourself =)