相关疑难解决方法(0)

访问"Google.Apis.Auth"路径被拒绝

我正在用Visual Studio 2013创建一个.net web api(.net 4.5),它调用Google.Apis.YouTube.v3来搜索视频.当我使用IIS Express(例如http:// localhost:12345 /)时,一切正常,但是一旦我改为使用本地IIS(例如http:// localhost/HelloWorldWebApi),它就会抛出一个System.UnauthorizedAccessException {"访问"Google.Apis.Auth"路径被拒绝."}.

我在网上搜索了几个小时,一无所获.

我的开发环境:Windows 8.1,Visual Studio 2013,IIS 8.5

代码:

    public IEnumerable<MyVideo> Get(string search)
    {
        try
        {
            string resourceName = "HelloWorldWebApi.client_secret.json";
            using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
            {
                Credential(stream).Wait();
            }

            YouTubeService youtube = new YouTubeService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = _credential,
                ApplicationName = "HelloWorldWebApiTest"
            });

            SearchResource.ListRequest listRequest = youtube.Search.List("snippet");
            listRequest.Q = search;
            listRequest.MaxResults = 5;
            listRequest.Type = "video";
            SearchListResponse searchResponse = listRequest.Execute();

            List<MyVideo> videos = new List<MyVideo>();
            foreach (SearchResult result in searchResponse.Items)
            {
                videos.Add(new …
Run Code Online (Sandbox Code Playgroud)

.net iis oauth-2.0 iis-express asp.net-web-api

6
推荐指数
1
解决办法
2293
查看次数

将ASP.NET部署到Windows Azure云,应用程序在云上运行时会出错

我正在尝试在Windows Azure云中部署ASP.NET应用程序.我正在为应用程序中的一个调用使用Google API.当我这样做时,我收到以下错误:

System.UnauthorizedAccessException:拒绝访问路径'Google.Apis.Auth'

ASP.NET无权访问所请求的资源.考虑将资源的访问权限授予ASP.NET请求标识.ASP.NET具有基本进程标识(IIS 5上通常为{MACHINE}\ASPNET,IIS 6和IIS 7上为网络服务,IIS 7.5上已配置的应用程序池标识),如果应用程序未模拟,则使用该标识.如果应用程序模拟通过,则标识将是匿名用户(通常为IUSR_MACHINENAME)或经过身份验证的请求用户.

要授予对文件的ASP.NET访问权限,请在"文件资源管理器"中右键单击该文件,选择"属性",然后选择"安全"选项卡.单击"添加"以添加适当的用户或组.突出显示ASP.NET帐户,并选中所需访问的框

我试过研究这个,但所有的建议都谈到了改变IIS服务器的设置,我不相信我有权访问,因为它在云中运行.有人可以帮忙吗?

编辑:这是给出错误的函数的代码:

 Async Function SpecialTest() As Task(Of String)

    Dim credential As UserCredential
    Dim clientSecretsPath As String = Server.MapPath("~/App_Data/client_secret.json")
    Dim scopes As IList(Of String) = New List(Of String)()
    scopes.Add(CalendarService.Scope.Calendar)
    Dim stream As FileStream = New FileStream(clientSecretsPath, System.IO.FileMode.Open, System.IO.FileAccess.Read)

    Using stream
        credential = Await GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets, scopes, "user3", CancellationToken.None)
    End Using


    Dim baseInitializer = New BaseClientService.Initializer()
    With baseInitializer
        .HttpClientInitializer = credential
        .ApplicationName = "P1"
    End With

    Dim service = New CalendarService(baseInitializer)


    Dim Calendars …
Run Code Online (Sandbox Code Playgroud)

vb.net asp.net iis azure google-api-dotnet-client

5
推荐指数
1
解决办法
3025
查看次数