Scenario:
Wrote a small Silverlight application which was trying to display the title of the site using Client Object Model and to my surprise I got the following error :
{System.Security.SecurityException ---> System.Security.SecurityException: Security error.
at System.Net.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.BrowserHttpWebRequest.<>c__DisplayClass5.
at System.Net.AsyncHelper.<>c__DisplayClass2.
--- End of inner exception stack trace ---
at System.Net.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
at System.Net.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)
at System.Net.WebClient.OpenReadAsyncCallback(IAsyncResult result)}
Solution:
This can be because of few reasons
1. Make sure the web URL used to create the Client context object exist and brows-able.
2. This might be because of missing client policy access file missing for the SharePoint Web Application not allowing you to connect. Create a new XML file named ClientAccessPolicy.xml with content below and save it to 'C:\inetpub\wwwroot\VirtualDirectories\80'
Note : Update policy file and port number as needed.
ClientAccessPolicy.xml:<?xml version="1.0" encoding="utf-8" ?>
Once you have the file copied to right location, do an IISReset and make sure you can access the file using following url :
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="*">
<domain uri="*" />
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true" />
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
http://servername:portno/clientaccesspolicy.xml
Note
This setting is only for Development Environment. Read the following article how to tweak the policy file for production environment.
Article:MSDN
Thursday, May 27, 2010
Subscribe to:
Post Comments (Atom)
3 comments:
Great solution.
We were facing same error and taking your steps mentioned resolved the issue.
Great solution.
It solved our problem.
Thanks man...good solution. Saves me a lot time for debugging my project!
Post a Comment