我已阅读this tutorial有关如何将Google Analytics与C#结合使用的信息。
我想在我的ASP.NET5应用程序中使用它,我想做得对。我需要使用服务帐户身份验证(我的应用程序将获取统计数据并将我生成的预设报告提供给用户)。
Google以2种形式提供证书
我正在考虑从JSON证书中提取值并将它们置于配置中,但是我必须设置X509Certificate2
,它只需要P12文件的路径,或构造函数中的一些神秘的byte[] rawData
。
var certificate = new X509Certificate2(pathToP12File, "myPassword", X509KeyStorageFlags.Exportable);
var credential = new ServiceAccountCredential( new ServiceAccountCredential.Initializer(serviceAccountEmail) {
Scopes = scopes}.FromCertificate(certificate));
任何想法该怎么做?
答案 0 :(得分:0)
对于WebApp,请转到Azure Portal:
使用类似于下面的代码来检索证书(注意 - 在WebApps中,证书存储在if (mysqli_connect_errno($con)) {
print_r("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if(isset($_POST["submit"])){
$name = mysqli_real_escape_string($con, $_POST['name']);
$company = mysqli_real_escape_string($con,$_POST['company']);
$email = mysqli_real_escape_string($con,$_POST['email']);
$comment = mysqli_real_escape_string($con,$_POST['comment']);
// Insert our data
$query = mysqli_query($con, "INSERT INTO `contacts` (`name`, `company`, `email`, `comment`) VALUES ('$name', '$company', '$email', '$comment')");
if($query) {
print_r('Success');
} else {
print_r('Query Failed');
}
mysqli_close($con);
}
中:
StoreLocation.CurrentUser
Web / Worker角色类似,通过门户网站(1)将证书上传到Cloud Service并跳过(2)。对于(3),请注意Web / Worker角色中的证书存储在var thumb = "your-certificate-thumbprint";
var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
var cert = store.Certificates.Cast<X509Certificate2>().FirstOrDefault(xc => xc.Thumbprint == thumb);
if (cert == null)
{
throw new Exception(string.Format("Could not find a certificate with thumbprint {0} in StoreName.{1} at StoreLocation.{2}", thumb, store.Name, store.Location));
}
。