简体   繁体   中英

Access to the path is denied. google api local iis publish

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

尝试以管理模式运行Visual Studio。

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM