简体   繁体   English

拒绝访问路径。 谷歌api本地iis发布

[英]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. 当我必须为Google用户验证身份验证时,无法访问某些文件夹。

Im getting the error: Access to the path '..' is denied when I've published locally on the IIS. 我收到错误消息:在IIS上本地发布时, Access to the path '..' is denied

I tried to change the folder location, so it would be in the App_Data of the project - no luck. 我试图更改文件夹位置,因此它将位于项目的App_Data中-祝您好运。

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. ,其中folderpath来自Server.MapPath("~/App_Data") ,并且_currentAccountNo是唯一的。 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%. FileDatastore默认将文件放入%appData%中。 Normally I would do something like. 通常我会做类似的事情。 (lets assume I use "_currentAccountNo" as well) (假设我也使用“ _currentAccountNo”)

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. 将目录发送到fileDataStore只会创建一个目录,其中包含您发送到fileDataStore的目录的名称,格式为%appdata%,这可能不是您想要的。

You might want to look into using LocalFileDataStore instead or better yet create your own implementation of idatastore. 您可能想研究使用LocalFileDataStore,或者更好地创建自己的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. 如果IIS可以访问%appdata%目录,则如何设置IIS是很棘手的。 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. 例如,如果内存服务Azure只能访问temp目录。

I've solved this locally while using IIS. 使用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 应用程序池中的高级设置的图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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