I come here as a last resort, I don't know what the hell happened. I restored my server battery and I've got the whole thing working, besides a provider hosted app that I made before. when I deployed it again from the same Visual Studio project, I couldn't access it anymore. Whatever account I am using, it will not work.
The part that hence the server to respond error 403 is when I get the context and then I Load and execute a query in the C# code behind of my aspx page : Here is the relevant part of the code which was working but doesnt work now :
Uri hostWeb = new Uri(Request.QueryString["SPHostUrl"]); using (ClientContext context = new ClientContext(hostWeb)) { Web web = context.Web; List ourList = null; try { ourList = web.Lists.GetByTitle(LIST_NAME); } catch (IOException ex) { Console.WriteLine(ex.Message); } CamlQuery itemFilter = new CamlQuery(); itemFilter.ViewXml = "<View><Query></Query><RowLimit>10</RowLimit></View>"; Microsoft.SharePoint.Client.ListItemCollection currentItems = ourList.GetItems(itemFilter); context.Load(currentItems); context.ExecuteQuery(); i tried so many things that I almost got a headache.
- Changed the app rights.
- Verified that the ClientId were the same in the Web.config( the secret was the same too), appmanifest, and AppReg Sharepoint form.
- Changed my way to get the context (tried the ways described here : http://blogs.msdn.com/b/kaevans/archive/2013/09/24/introducing-sharepointcontext-for-provider-hosted-sharepoint-apps.aspx) : here I got either a 401 error or a "The parameter 'token' cannot be a null or empty string" error) on this I googled and followed the tips from the first result page : nothing more.
- I changed services and pool owners, tried to disable OAuth over HTTPS, ...
- Tried to redo a fresh new app with only the code to get context in the 4 ways (TokenHelper S2S or ACS, new ClientContext(hostweb), SPContext.Current ...) NO WAY TO MAKE IT WORK, always errors 403 or null token.
- I made a pfx certificate and attached it to the app web, filling the details in Web.config.
- Tried different web browser
- I also checked the logs from Sharepoint : got a few tips like "can't write the Distributed Cache" or "App token requested from appredirect.aspx for site "myssite" but there was an error on generating it". SAME HERE the tips were not useful for my case on the internet. I tried reboot the server battery service distributed cache, changing owner, ... still nothing.
EDIT 1 : In the LOGS I also spotted "Error when get token for app i:0i.t|ms.sp.ext|7bfc14e7-057b-4b98-8b16-351222de0351@5cad9afa-9d0b-47bf-9db9-a3b157cf48b1, exception: Microsoft.SharePoint.SPException: The Azure Access Control Service is unavailable.". But I don't want to contact an Azure service, I want to authenticate from the SharePoint site accounts, which are bound to a local Active Directory.
EDIT 2 : I also tried to recreate the Trusted Root Authority and the Trusted Security Token Issuer on the server with a valid pfx certificate and also I put the correct references into the Web.config file of App web. I successfuly re-registered the app and all the nameid and id was correct. But still no changes.
Tried to give full rights permission to users, IIS user to the web directory, but doesn't worked too.
In this app all I used to do was to get some elements from a list and it WORKED before the restore backup. Nothing else is changed besides this, can someone help me to find out whats wrong ? thanks a lot
context.Credentials = new System.Net.NetworkCredential("ACCOUNT","PASSWORD","DOMAIN");with a domain account, it works. When I manually define correct context credentials it will work. So maybe it doesnt succeed to automatically retrieve current user logged in ... dive deeper