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. Did someone know where the problem is.

Thanks

  • 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. – Michael West Apr 20 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 Apr 24 at 14:41
  • Great. Please answer your own question and accept it when you are allowed to. This may help someone in the future. – Michael West Apr 24 at 14:44
up vote 0 down vote accepted

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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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