sharepoint 2016 access denied issue - c#

First of all, I am trying to retrieve decent webinfo of my web application however I received Access denied error and the error is coming from site collection “sitemaster-a118466c-660d-479c-873f-af6284910724” as screen shot below
I never create “sitemaster-a118466c-660d-479c-873f-af6284910724” as my site collection, so I suspect it is bundle with “Publishing” template.
Below is the sample code that I use to retrieve my decent webinfo, and I have my access denied error here.
SPSecurity.RunWithElevatedPrivileges(delegate ()
{
using (SPSite site = new SPSite(SiteCollectionUrl))
{
//code to retrieve my web application decent info
}
}
Once I face this I wanted to update ““sitemaster-a118466c-660d-479c-873f-af6284910724” site collection administrator users however I cannot find it from sharepoint centraladmin site.

Related

Get Sharepoint Online Site using C# Graph SDK

I'm trying to use the Graph SDK to get a specific Sharepoint site by URL so I can read and write the list, create document libraries, and add documents to existing libraries.
This works to get the root:
var site = await graphClient.Sites[SPUrl].Request().GetAsync();
This doesn't work to get the site I want:
var site = await graphClient.Sites[SPUrl+"/segment1/segment2/site"].Request().GetAsync();
And this doesn't work to get the site by URL -- it tells me "the provided path does not exist or does not represent a site":
var siteByPath = await graphClient.Sites[SPUrl].SiteWithPath("/segment1/segement2/site").Request().GetAsync();
But using the Graph Explorer, this works:
https://graph.microsoft.com/v1.0/sites/my.site.com:/sites/segment1/segment2/site?$select=id
Using the Graph Explorer I determined that each segment of the URL is considered its own site, but didn't have any luck doing this -- the error is "provided identifier is malformed - id is not valid":
var site = await graphClient.Sites[SPUrl].Sites["segment1"].Request().GetAsync();
What am I missing?
With the Sharepoint CSOM you could just ask for a site by its URL. My application is in Azure now and being authenticated by through OAuth tokens, not by a username and password handled within the application, so I'm not sure I can pass that authentication through CSOM. As far as I can tell I need to use Graph now.
It would appear that the problem was that if you're going to query the sites under a site root, you need to add the ":" to your original root site string. So
"await graphClient.Sites[SPUrl].Sites["/segment1/segment2/site"].Request().GetAsync();" needs to be
"await graphClient.Sites[SPUrl+":"].Sites["/segment1/segment2/site"].Request().GetAsync();" which would make it match the syntax used in the Graph Explorer.
I had assumed that asking for a Site using the SDK would handle that, but I was wrong.

Office 365 REST API - Outlook User Photo

I'm attempting to retrieve other users' outlook photos using the Office 365 REST API (Preview). The documentation is here on this page: https://msdn.microsoft.com/en-us/office/office365/api/photo-rest-operations.
I'm able to successfully retrieve my own photo using an access token by making the following rest call:
GET https://outlook.office365.com/api/beta/me/userphoto/$value
However, when attempting to retrieve the photos of other people in my organization by using this REST call:
GET https://outlook.office365.com/api/beta/Users('{user_id}')/userphotos('{size}')/$value
I get the following error:
{
"error": {
"code": "ErrorAccessDenied",
"message": "Access is denied. Check credentials and try again."
}
}
This error isn't listed anywhere in the documentation as far as I can tell. I suspect this has something to do with the permissions in Azure but that's only a guess. Maybe it isn't supported in the preview API? Anyone have any ideas?
nkorai, you are right, the current permission set does not allow you to see others photo. We are adding a new oauth permission to the exchange online application endpoint which will allow you to do this. We are in the process of getting this permission enabled. Hopefully in a few weeks.

changing sharepoint trust on application page

Good day.
So ive been reading on how it is bad "practice" to set a SharePoint applications trust to full. Due to this hackers are able to infiltrate you web app. what if though there are pages or web parts that require full trust to function correctly?!
In my case i want to elevate the trust on a coded application page and maybe a custom web part. Are there any ideas on how one would go about doing that in code?
Your help will be much appreciated.
Use SPSecurity.RunWithElevatedPrivileges() method to run any code in your application page with elevated privileges for unprivileged user
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(web.Site.ID))
{
// implementation details omitted
}
});
It is important to create new SPSite object and SPWeb object inside delegate. Do not reuse existing SPSite object and SPWeb object because they are created with restricted permissions

C# FaceBook error, Error Message: next is not owned by the application

This is a one page site I'm using to understand FB. I'm trying to get FB Connect to work.
I've tried several tutorials, two different domains, and tweaked the app settings on FB. All I seem to be able to get is the above error message.
I've read several answers on this site but my FB app setting don't match the any of the answers.
Thanks!
use should use Facebook rest api.And make sure that you have registered your website at facebook to connect, and you should have ApplicationKey and SecretKey.
and to connect facebook
<fb:login-button onlogin="window.location.reload()"></fb:login-button>
Then for access permission
Collapse | Copy Code
<fb:prompt-permission perms="email"> allow mail permission</fb:prompt-permission>
Add reference facebook api in your project.
ConnectSession connectSession = new ConnectSession
(ConnectAuthentication.ApiKey,ConnectAuthentication.SecretKey);
if(connectSession.IsConnected==true)//you sucessfully connected

Programmatically accessing a PKI sharepoint portal

I am having trouble doing something simple like the following
using (SPSite site = new SPSite(topLevelSite))
{
SPWeb rootWeb = site.OpenWeb();
SPWeb newWeb = rootWeb.Webs.Add(siteName, "abc", "abc",1033,template,false,false);
}
But the catch I am trying to add a site to a PKI enabled sharepoint site:
This code works fine when I am dealing with my non pki sharepoint server, but I get the error:
"
The Web Application at https://server/sites/newSite could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system admin may need to add a new request URL mapping to the intended application.
"
My main question is: How do you go about accessing with C# a sharepoint site that is PKI enabled? Do I need to insert my certs somewhere programmatically or what?
Are there steps before I open SPSite, or are there other Objects I need to use that are more PKI friendly?
I would first make sure that the URL you use is the same URL SharePoint itself knows about. This thing is called Alternate Access Mapping and is accessible through the Central Administration. Sometimes people would map the web application to a different URL using DNS and IIS configuration only, without updating SharePoint itself. It might appear to be working correctly when browsing the site, but this kind of error would appear when using the API

Categories