Share via

HTTP Client From Network Share

reuvygroovy 781 Reputation points
2022-02-13T16:42:45.857+00:00

We have the following code
using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace Console99
{
    internal class Program
    {
        public Program()
        {
        }

        private static void Main(string[] args)
        {
            try
            {
                using (HttpClient client = new HttpClient(new HttpClientHandler()
                {
                    UseDefaultCredentials = true
                }))
                {
                    var result = client.GetAsync("https://server/WS/api/UsersApi?id=012314");
                    var a = result.Result.StatusCode;
                    Console.Write("hello: " + a);
                }

            }
            catch (Exception exception)
            {
                Console.Write(exception.StackTrace);
            }
            Console.ReadKey();
        }
    }

When the code runs from a user with Local Admin permissions, it works OK. When a 'limited' user runs the code, it fails. What is strange though is after a local admin has ran the code, the regular user now may run the code. It seems like this first admin-run does something to allow the following users to run it.

Any idea what this could be?

I should note, this happens when we run an app from a network share. when the same user runs the same code from his local PC it works fine.

Windows for business | Windows Client for IT Pros | Networking | Network connectivity and file sharing
0 comments No comments

1 answer

Sort by: Most helpful
  1. Limitless Technology 40,106 Reputation points
    2022-02-18T14:28:05.203+00:00

    Hello @reuvygroovy

    This is obviously related to NTFS permissions over the location of the script. Once used the admin, it caches the "Execute" permission and then the user has access since probably you already gave the user Read/Write on the location.

    To verify this, try to enable "Full Control" to the standard user over the script file in the network location.

    Hope this helps with your query,

    ------
    --If the reply is helpful, please Upvote and Accept as answer--

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.