Programmatically accessing a PKI sharepoint portal - c#

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

Related

Client added new sandbox for Dynamics 365, and when trying to insert data I'm getting a 401 error

We had our client create a new sandbox for us to test imports without workflows (imports work on the original sandbox.) I'm authenticated into D365 using an Active Directory app with a certificate sent from the C# code and my thought process was to just replace all instances of the old base url of {sandbox-name}.api.crm.dynamics or {sandbox-name}.crm.dynamics with {new-sandbox-name}.api.crm.dynamics and {new-sandbox-name}.crm.dynamics. I'm getting a 401 error now when trying to import data.
I can't find in the Active Directory app where the certificate that we created is tied only to that original sandbox url, so is there something obvious I'm missing?
In your new Sandbox D365 CRM, go and create the Application user in system user table with the right security role/privilege. Then it should work.
Read more

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.

sharepoint 2016 access denied issue

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.

Facebook login throws "Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed

I know this question was already asked many times, but still It seems to throw this error altough I tried several url addresses.
I'm trying to make facebook login through a asp.net mvc app like in microsoft tutorial
here.
When I check it on local host it works fine (Site URL in facebook is set to: http://localhost:55797/
but when I try to check it after I upload the app to the server it gives me this error:
Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains.
My server's login page is: http://proj.ruppin.ac.il/igroup20/test1/Account/Login.aspx
I tried to write the following in my facebook app settings Site URL:
*http://proj.ruppin.ac.il/
*http://proj.ruppin.ac.il/igroup20/
*http://proj.ruppin.ac.il/igroup20/test1/
*http://proj.ruppin.ac.il/igroup20/test1/Account/
*http://proj.ruppin.ac.il/igroup20/test1/Account/Login.aspx
but none of them works for me.
this is my AuthConfig.cs:
public static void RegisterOpenAuth()
{
// See http://go.microsoft.com/fwlink/?LinkId=252803 for details on setting up this ASP.NET
// application to support logging in via external services.
//OpenAuth.AuthenticationClients.AddTwitter(
// consumerKey: "your Twitter consumer key",
// consumerSecret: "your Twitter consumer secret");
OpenAuth.AuthenticationClients.AddFacebook(
appId: "474928559284763",
appSecret: "****"); //hidden just for this question
//OpenAuth.AuthenticationClients.AddMicrosoft(
// clientId: "your Microsoft account client id",
// clientSecret: "your Microsoft account client secret");
//OpenAuth.AuthenticationClients.AddGoogle();
}
EDIT:
those are the screens that seems relevant to me, but I seem to have different gui, not like Tommy for example down here in this post:
EDIT2:
I just noticed there is a place for app domains and wrote there "proj.ruppin.ac.il" and in the web site url: "http://proj.ruppin.ac.il/igroup20/test1/" but still same error
For the benefit of searchers, I had the same when creating a test version of a site.
The answer was to go into the facebook site > Apps > My App > Settings > 'Advanced' tab and add the localhost address in the section titled 'Valid OAuth redirect URIs'.
Note: The same style of work will be required for an xyz.azurewebsites.net domain as well as a .com when you are testing.
Try this! These steps worked for my fb app hosted locally on http://localhost:3000/
Once signed in to your app on developers.facebook.com/...
Click Settings > Basic
Leave the "App Domains" field blank.
Click + Add Platform > Website
Use http://localhost:3000/ for both "Site URL" and "Mobile Site URL" fields
Click Save Changes
FINALLY!
You will need to update your App Domains as well in the Facebook Application configuration module to proj.ruppin.ac.il (Image taken from referenced tutorial to show that there are 2 places to update when changing FB app login URL)
Here's all the things I did to get this working
Nothing in "App Domains"
Put the server name (with port) in "Site URL"
In the "App Details" tab turn on your "Website" (I have the mobile website on) http://cl.ly/image/0h0D0L050Z2v (Why is this separate from setting the URL?)
Quadruple check your appid. I swear mine changed. But maybe I'm hallucinating that.
I got it to work with example.com in the settings. No http://www. It should work for you too (and you can add more that one domain.
Your issue is with your Facebook JavaScript SDK implementation and your Facebook app settings. The JS SDK is failing to initialize because it's been given the "wrong" settings.
The App Domain should be proj.ruppin.ac.il, and the Site URL should be http://proj.ruppin.ac.il/igroup20/test1/. It appears you've already done that. If so, make sure it saved properly, and you're not receiving any validation issues.
Lastly, go to your Facebook App's "Dashboard" and look for any warnings. For example, you may see Sandbox Mode is enabled; you may need to disable it before you can use the Facebook JS SDK.
Like others, I'm still seeing the "old" Facebook apps panel, but if you could provide a full screen capture of the "Dashboard" and "Settings" panes, we could be more helpful.
For the errors like top level domains are not allowed we need to provide both website and mobile url along with port number this works for me fine
you just need to also include the port number for your local host.
you can give the url like this:
1. https://developers.facebook.com/x/apps/662194763843967/settings/
Add your dome at App Domains in app settings
see don't use http://
suppose your domain is
http://localhost/abhinav/
then write localhost/abhinav/
click on add platform
let say its a web app
write your full site url at website text-box
Site URL : http://localhost/abhinav/
Below is the reference image where you can see what should you place at App Domains
http://i.stack.imgur.com/qZVkk.png\
So,there is some bug in Facebook and its APIs-
There is currently a bug which will prevent Facebook Login for Windows Phone
from working if you have any entries in
the "Valid OAuth redirect URIs" field in the Advanced section of your app settings.
This can be worked around by adding "https://m.facebook.com/dialog/return/ms"
in this field.
Try different links this one worked for me
"http://www.facebook.com/"

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

Categories