0

I'm having trouble getting access to some folders, when I have to validate an authentication for a Google user.

Im getting the error: Access to the path '..' is denied when I've published locally on the IIS.

I tried to change the folder location, so it would be in the App_Data of the project - no luck.

I have also tried to do what these guys are doing, but didnt help as well.

My code looks like:

            string path = AppDomain.CurrentDomain.BaseDirectory + @"\Json\client_secrets.json";

            using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read))
            {

                try
                {
                    string googlecalendarpath = folderpath + @"\App_Data\GoogleCalendar";

                    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                        GoogleClientSecrets.Load(stream).Secrets, scopes,
                        _currentAccountNo,
                        //Vær sikker på, at dette er det samme altid, og er unikt, da ens permissions til Google Calendar bliver bundet op på dette!
                        CancellationToken.None, new FileDataStore(googlecalendarpath)).Result;
                }
                catch (Exception ex)
                {
                    return "Cred. FEJL: " +ex.GetFullExceptionString();
                }
            }

, where folderpath is from Server.MapPath("~/App_Data"), and _currentAccountNo is unique. I cannot see what i'm missing when following the examples online, and can't see what I'm doing wrong.

  • thanks
Community
  • 1
  • 1
Moelbeck
  • 591
  • 2
  • 7
  • 29

3 Answers3

0

Try Running Visual Studio as Admin Mode.

Anjani
  • 997
  • 1
  • 7
  • 9
  • I am. And it is not when I'm debugging, its when I have deployed to site locally. When debugging it is working just fine. – Moelbeck Jul 08 '15 at 07:45
  • Ok, then i suggest you to try by giving folder permission to everyone. – Anjani Jul 08 '15 at 07:48
  • Tried to give these users read/write permission: Everyone, Authenticated Users, Local account, IUSR, Local Service, Network Service, Users, IIS_IUSR.. Didnt help :( – Moelbeck Jul 08 '15 at 09:10
  • @MothCreek did you ever find a solution to this. I have exactly the same problem. Works with IIS Express the minute i change to IIS hosted i get an exception. – Piotr Stulinski Oct 12 '15 at 16:42
0

FileDatastore puts files by default in %appData%. Normally I would do something like. (lets assume I use "_currentAccountNo" as well)

new FileDataStore("Console.Analytics.Auth.Store")  

Then when I call it I get a directory called

%AppData%\Roaming\Console.Analytics.Auth.Store

in that directory now lives a file called

Google.Apis.Auth.OAuth2.Responses.TokenResponse-[account Num]

Sending a directory to fileDataStore is just going to make a directory with the name of the directory you sent to fileDataStore in %appdata%, which probably isn't what you intended.

You might want to look into using LocalFileDataStore instead or better yet create your own implementation of idatastore.

I am not sure if this is your problem or not. It is tricky how you have IIS set up if it has access to the %appdata% directory or not. It depends upon what user you have it set to and what app pool its running as. If memory services azure for example only has access to the temp dir.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • I tried to use the Roaming folder in the beginning, but I still got a 'access denied' error. And that's why I was trying to use another folder, but I still get the same error. Trying right now with the LocalFileDataStore implementation, but with no luck so fare. I've also tried to grant read/write access to the folder to everyone - nothing yet. – Moelbeck Jul 08 '15 at 08:22
  • and we are sure its not the access to the json file its complaining about? – Linda Lawton - DaImTo Jul 08 '15 at 08:41
  • Yes, I tried to do like they did in the 'Google-Dotnet-Sample-master' project, where they instanciates the CLIENT_ID and CLIENT_SECRETS locally in strings. still working in debugging mode, but gets 'access is denied' when published locally. – Moelbeck Jul 08 '15 at 08:59
  • And I'm not sure if I'm missing to grant some users read/write access to the folders. These users have it: Everyone, Authenticated Users, Local account, IUSR, Local Service, Network Service, Users, IIS_IUSR. – Moelbeck Jul 08 '15 at 09:02
  • If the file 'Google.Apis.Auth.OAuth2.Responses.TokenRespons..' is in the folder before I run a published version, it works fine. But I cannot write to it. And I have tried to grant read/write access to all now, for that folder. – Moelbeck Jul 08 '15 at 09:35
  • @Moelbeck, did you fix or find a workaround to your issue ? I've build specifically each url and perform webrequests in order to get token and refresh and so on, this works but is not nice. API did not work for me :( – Fer R Mar 20 '18 at 20:05
  • I got it working by setting it to the current working directory – Linda Lawton - DaImTo Mar 20 '18 at 20:57
0

I've solved this locally while using IIS.

Change the Advanced settings of the Application Pool - Identity. Use your login user instead of "Application pool" or "Network" or "Local".

Image of Advanced settings in Application Pool