0

I know that my question is similar to other questions here, but I think I have a different scenario. I'm trying to upload some css files to sitecore (in my case Sc 9.0.1) by calling this url using

WebClient() "/sitecore modules/PowerShell/Services/RemoteScriptCall.ashx?user=sitecore\******&password=*&script=\Themes\ExampleProject\ExampleProject Main Theme/styles&sc_database=master&apiVersion=media&scriptDb=master".

This is my code:

public string Upload(string filePath)
    {
        if (!Directory.Exists(Directory.GetParent(filePath).FullName))
            return $"The file {filePath} could not be found";
        using (var webClient = new WebClient())
        {
            string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes($"username:password"));
            webClient.Headers[HttpRequestHeader.Authorization] = string.Format("Basic {0}", credentials);
            webClient.Headers.Add("user-agent", @"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36");
            webClient.Headers.Add("Accept", "*/*");
            webClient.Credentials = new NetworkCredential("*****", "*", "sitecore");
            byte[] responseArray = webClient.UploadFile(_targetUri, "POST", filePath);
            return filePath;
        }
    }

As an answer from the server, I got, the error 403 (Forbidden) although I entered the admin credentials of the site.

Does someone know where the problem is?

Thanks

3
  • You are trying to upload to the Sitecore PowerShell Extensions web service. The following page covers how to use the SPE Remoting Module to upload files. doc.sitecorepowershell.com/remoting . You may also need to review the security page doc.sitecorepowershell.com/security. Commented Apr 20, 2018 at 19:57
  • Hi Michael, thanks for your answer. I found out where the problem is, some parameters where missing. The target database, api version and scriptdatabase. "&sc_database=master&apiVersion=media&scriptDb=master". So i added these parameters to the url and it works.
    – Najem
    Commented Apr 24, 2018 at 14:41
  • Great. Please answer your own question and accept it when you are allowed to. This may help someone in the future. Commented Apr 24, 2018 at 14:44

1 Answer 1

1

I found out where the problem is, some parameters where missing. The target database, api version and scriptdatabase. "&sc_database=master&apiVersion=media&scriptDb=master". So i added these parameters to the url and it works

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.