- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个非常奇怪的问题。我将 webrole 发布到 azure 云服务。在这个项目中,它需要 webrole 调用 Azure Rest API,我可以在本地模拟器中获得响应,但是,如果我将其发布到 Azure,我会收到 403 禁止错误。我确信我已将证书安装到 Azure。
可以通过以下步骤重现此错误:
控制台应用程序代码:
static void Main(string[] args)
{
try
{
// X.509 certificate variables.
X509Store certStore = null;
X509Certificate2Collection certCollection = null;
X509Certificate2 certificate = null;
// Request and response variables.
HttpWebRequest httpWebRequest = null;
HttpWebResponse httpWebResponse = null;
// Stream variables.
Stream responseStream = null;
StreamReader reader = null;
// URI variable.
Uri requestUri = null;
// Specify operation to use for the service management call.
// This sample will use the operation for listing the hosted services.
string operation = "hostedservices";
// The ID for the Windows Azure subscription.
string subscriptionId = "";
// The thumbprint for the certificate. This certificate would have been
// previously added as a management certificate within the Windows Azure management portal.
string thumbPrint = "";
// Open the certificate store for the current user.
certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
certStore.Open(OpenFlags.ReadOnly);
// Find the certificate with the specified thumbprint.
certCollection = certStore.Certificates.Find(
X509FindType.FindByThumbprint,
thumbPrint,
false);
// Close the certificate store.
certStore.Close();
// Check to see if a matching certificate was found.
if (0 == certCollection.Count)
{
throw new Exception("No certificate found containing thumbprint " + thumbPrint);
}
// A matching certificate was found.
certificate = certCollection[0];
Console.WriteLine("Using certificate with thumbprint: " + thumbPrint);
// Create the request.
requestUri = new Uri("https://management.core.windows.net/"
+ subscriptionId
+ "/services/"
+ operation);
httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(requestUri);
// Add the certificate to the request.
httpWebRequest.ClientCertificates.Add(certificate);
// Specify the version information in the header.
httpWebRequest.Headers.Add("x-ms-version", "2011-10-01");
// Make the call using the web request.
httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
// Display the web response status code.
Console.WriteLine("Response status code: " + httpWebResponse.StatusCode);
// Display the request ID returned by Windows Azure.
if (null != httpWebResponse.Headers)
{
Console.WriteLine("x-ms-request-id: "
+ httpWebResponse.Headers["x-ms-request-id"]);
}
// Parse the web response.
responseStream = httpWebResponse.GetResponseStream();
reader = new StreamReader(responseStream);
// Display the raw response.
Console.WriteLine("Response output:");
Console.WriteLine(reader.ReadToEnd());
// Close the resources no longer needed.
httpWebResponse.Close();
responseStream.Close();
reader.Close();
}
catch (Exception e)
{
Console.WriteLine("Error encountered: " + e.Message);
// Exit the application with exit code 1.
Console.ReadLine();
System.Environment.Exit(1);
}
finally
{
// Exit the application.
Console.ReadLine();
System.Environment.Exit(0);
}
}
最佳答案
我使用您提供的 azure create cert 链接遇到了同样的问题。我发现使用该方法创建证书时,私钥没有上传到云服务。即使服务能够找到证书,但在提交请求时仍然未经授权。
使用以下方法创建私钥和公钥证书是有效的。在 Visual Studio 命令提示符中,创建 .cer
和 .pfx
文件:
makecert -r -pe -n "CN=AzureManage" -sky exchange "AzureManage.cer" -sv "AzureManage.pvk"
pvk2pfx -pvk "AzureManage.pvk" -spc "AzureManage.cer" -pfx "AzureManage.pfx" -pi password
第一个命令创建一个私钥和公钥文件。系统将多次提示您输入密码。第二个命令将两者组合成一个 pfx 文件。如果您关闭-pi密码
,那么系统将提示您输入密码,而不是在终端中输入密码。
然后您需要适本地导入文件:
然后您可以按如下方式使用 Azure 管理 REST API:
X509Certificate2 GetCertificate(string thumbprint)
{
var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
var certs = store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);
if (certs.Count == 0) return null;
var cert = certs[0];
store.Close();
return cert;
}
HttpWebRequest request = WebRequest.CreateHttp(apiUrl);
request.ClientCertificates.Add(cert);
request.Headers.Add("x-ms-version", "2012-03-01");
关于azure - 403 禁止从 Web 角色实例调用 Azure Rest api 时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19850742/
我正在尝试使用 npmpublish 命令发布包。但我每次都会收到此错误。 npm ERR! code E403 npm ERR! 403 Forbidden - PUT https://regist
我在 WAMP 上访问我的本地主机(最后是 phpmyadmin)时遇到问题。 当我输入 localhost或 http://127.0.0.1进入我的浏览器,我收到以下消息: Forbidden Y
我正在尝试发送 $ajax,并且我已经得到了它,但是我必须使用我的表单发送文件,无论是否相同,都没关系。尚未找到 csrf token ,并且出现错误。 我的 JavaScript $(doc
我有一个奇怪的问题,我试图使用请求模块废弃某些页面,但这样做时我收到 403 访问被拒绝。但我完全能够使用 Node 的curl 模块来完成此操作。但互联网上的人们认为,它比请求模块更需要性能,因为我
所以,我正在制作一个公共(public)的不和谐机器人,但我的脚本的一部分有问题。我的 kick/ban 命令是用来完成的 $ban @user 它必须在 ping 中完成。由于这是公开的,我真的很想
我在负载均衡器后面有 2 个服务器。此 LB 上配置了 SSL。将近 50 个不同的客户端能够成功连接到我的网站,除了 1 个客户端从浏览器收到禁止 (403) 消息。 经过一番调查,我发现他在代理服
1、禁止计算局部梯度 torch.autogard.no_grad: 禁用梯度计算的上下文管理器。 当确定不会调用Tensor.backward()计算梯度时,设置禁止计算梯度会减少内存消耗。
如果 Moose 的构造函数调用中有额外的参数不是属性,有没有办法死?例如,这个: package Shoe; use Moose; has 'size' => (is => 'ro', isa =
在服务器上,安装了 Nginx。 Let's Encrypt 在 www.domain.com 上运行良好,但不适用于 static.domain.com 使用 PuTTY,当我输入时:sudo le
我使用 emacs 来编辑所有内容。在我的一些 LateX 文档中,我想在编辑表格和代码时自动禁用自动填充模式。基本上,我想要两个标签,例如: %%% BEGIN NO FILL %%%
通过 Nuget,我将 WindowsAzure.Storage 升级到 8.1.1。 然后,我下载了 AzureStorageEmulator 5.1.0.0 客户端。 我的连接字符串: UseDe
Qt documentation说,信号的返回值是不可能的: Signals are automatically generated by the moc and must not be implem
编辑版本 我有一个关于 GPG 的问题,但我写了所有的过程,也许它会对某人有所帮助。 我想:禁止 GPG 命令中的密码提示。 我不想:使用 -c 选项(--对称)。 我有 2 个系统 Linux 和
现在的想法是这样的:在 Java 中为 octalIntegerLiteral我有一个规则 octalNumeral, (integerTypeSuffix optional) 但我想得到一个数字作为
我在 Python 项目中所有模块的开头使用以下内容: import setup_loggers setup_loggers是一个可以做到这一点的模块。 import语句确保无论首先加载哪个模块,记录
我刚刚下载了最新版本的 XAMPP,PHP 版本为 7.2.4。我为 HTML 表单做了一个非常简单的 PHP 验证,当我按下提交时,它会出现以下内容: Access forbidden!You do
我已经成功运行 Vagrant 大约一个星期了。昨晚我运行了 vagrant reload,现在我无法再访问我的网站。 VirtualBox 版本 4.2.16 Vagrant 版本 1.2.7 我的
我使用以下 JavaScript 代码在完成 ajax 后播放音频: $(document).ready(function () { $.ajaxSetup(
我有一个似乎可以在互联网上运行的应用程序。但我接到了一位最终用户的电话,他在使用website时遇到困难。 我要求她发送控制台错误的屏幕截图并收到以下信息: 从 stackoverflow 搜索来看,
我在尝试提交到 svn 存储库时遇到此错误: svn: MKACTIVITY of '/svn/Demo/!svn/act/e2e65cfa-...4165f': 403 Forbidden (htt
我是一名优秀的程序员,十分优秀!