【发布时间】:2019-05-28 09:46:07
【问题描述】:
我使用 oauth 身份验证将联系人添加到 google Contacts api
当我部署到iis 时,我收到此错误:
“/”应用程序中的服务器错误。访问被拒绝 描述:一个 当前 web 执行过程中发生未处理的异常 要求。请查看堆栈跟踪以获取有关 错误及其源自代码的位置。
异常详细信息:System.ComponentModel.Win32Exception:访问权限为 拒绝
来源错误:
在执行过程中产生了一个未处理的异常 当前的网络请求。有关原产地和位置的信息 可以使用下面的异常堆栈跟踪来识别异常。
堆栈跟踪:
[Win32Exception (0x80004005): Access is denied]
System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) +604
System.Diagnostics.Process.Start(ProcessStartInfo startInfo) +60
Google.Apis.Auth.OAuth2.<ReceiveCodeAsync>d__16.MoveNext() +258
[NotSupportedException: Failed to launch browser with "https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&response_type=code&client_id=347204707806-a44e1b5q57mqr0bkvic9gd03ms52nk0c.apps.googleusercontent.com&redirect_uri=http%3A%2F%2F127.0.0.1%3A54450%2Fauthorize%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth2%2Fcontacts%20https%3A%2F%2Fwww.google.com%2Fm8%2Ffeeds" for authorization. See inner exception for details.]
Google.Apis.Auth.OAuth2.<ReceiveCodeAsync>d__16.MoveNext() +832
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +60
Google.Apis.Auth.OAuth2.<AuthorizeAsync>d__8.MoveNext() +701
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +60
Google.Apis.Auth.OAuth2.<AuthorizeAsync>d__4.MoveNext() +572
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +60
Google.Apis.Auth.OAuth2.<AuthorizeAsync>d__1.MoveNext() +426
string clientId = xxxxxxx.apps.googleusercontent.com";
string clientSecret = "xxxxxxxxxxxxxxxxxx";
string[] scopes = new string[] { "https://www.googleapis.com/auth/contacts" }; // view your basic profile info.
// Use the current Google .net client library to get the Oauth2 stuff.
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = clientId, ClientSecret = clientSecret }
, scopes
, "teste"
, CancellationToken.None
, new FileDataStore(Server.MapPath("/") + "Datastore", true)).Result;
try
{
// Translate the Oauth permissions to something the old client libray can read
OAuth2Parameters parameters = new OAuth2Parameters();
parameters.AccessToken = credential.Token.AccessToken;
parameters.RefreshToken = credential.Token.RefreshToken;
RequestSettings settings = new RequestSettings("contacts-241820", parameters);
ContactsRequest cr = new ContactsRequest(settings);
if (User.Identity.IsAuthenticated)
CreateContact(cr);
【问题讨论】:
-
您的 web.config 的内容是什么?可能存在与您的异常相关的设置。
-
在 Visual Studio 2017 和 IISExpress 上运行良好
标签: .net iis deployment oauth