Asp.net mvc 使用MVC列出集群(页面持续加载数小时)
使用“Loggedin”视图,我试图在订阅中列出HDInsight群集,但当我试图运行代码时,“Loggedin”页面一直在加载,没有任何输出。我无法找出哪里出了问题 调试时,代码挂起在Asp.net mvc 使用MVC列出集群(页面持续加载数小时),asp.net-mvc,azure-hdinsight,Asp.net Mvc,Azure Hdinsight,使用“Loggedin”视图,我试图在订阅中列出HDInsight群集,但当我试图运行代码时,“Loggedin”页面一直在加载,没有任何输出。我无法找出哪里出了问题 调试时,代码挂起在var cluster=client.ListClusters()行在控制器中。 在这种情况下,“输出”窗口显示以下消息: Microsoft.WindowsAzure.ServiceRuntime详细信息:500:角色实例状态检查启动Microsoft.WindowsAzure.ServiceRuntime详细
var cluster=client.ListClusters()行代码>在控制器中。
在这种情况下,“输出”窗口显示以下消息:
Microsoft.WindowsAzure.ServiceRuntime详细信息:500:角色实例状态检查启动Microsoft.WindowsAzure.ServiceRuntime详细信息:502:角色实例状态检查成功:就绪线程0x59fc已退出,代码为259(0x103)
任何帮助都将不胜感激
控制器
public ActionResult Loggedin()
{
Guid subscriptionId = new Guid("Subscription_id"); //your-subscription-id
string certName = "Friendly_name"; //your friendly name
// Create an HDInsight Client
X509Store store = new X509Store(StoreName.My);
store.Open(OpenFlags.ReadOnly);
X509Certificate2 cert = store.Certificates.Cast<X509Certificate2>().First(item => item.FriendlyName == certName);
HDInsightCertificateCredential creds = new HDInsightCertificateCredential(subscriptionId, cert);
IHDInsightClient client = HDInsightClient.Connect(creds);
var cluster = client.ListClusters();
var c = new List<ClusterList>();
foreach (var item in cluster)
{
c.Add(new ClusterList() { Name = item.Name });
c.Add(new ClusterList() { Node = item.ClusterSizeInNodes });
}
return View(c);
}
public async Task<ActionResult> Loggedin()
{
ViewBag.Message = "Your application description page.";
var c = new List<ClusterList>();
var call = Task.Factory.StartNew(() => c=GetAsync());
await call;
return View(c);
}
public List<ClusterList> GetAsync()
{
Guid subscriptionId = new Guid("your-subscription-id"); //your-subscription-id
string certName = "Friendly";//your-subscription-management-cert-name
// Create an HDInsight Client
X509Store store = new X509Store(StoreName.My);
store.Open(OpenFlags.ReadOnly);
X509Certificate2 cert = store.Certificates.Cast<X509Certificate2>().Single(item => item.FriendlyName == certName); //your friendly name
HDInsightCertificateCredential creds = new HDInsightCertificateCredential(subscriptionId, cert);
IHDInsightClient client = HDInsightClient.Connect(creds);
var cluster = client.ListClusters();
var c1 = new List<ClusterList>();
foreach(var item in cluster)
{
c1.Add(new ClusterList() { Name = item.Name, Node = item.ClusterSizeInNodes });
}
return c1;
}
看法
@型号列表
@{
ViewBag.Title=“Loggedin”;
Layout=“~/Views/Shared/_Layout.cshtml”;
}
洛格丁
@Html.Label(“名称”)
@Html.Label(“节点”)
@型号.名称
@模型节点
上的一篇帖子帮助我找到了确切的问题。
此外,这篇文章帮助我解决了这个问题
代码中的以下更改解决了此问题:
控制器
public ActionResult Loggedin()
{
Guid subscriptionId = new Guid("Subscription_id"); //your-subscription-id
string certName = "Friendly_name"; //your friendly name
// Create an HDInsight Client
X509Store store = new X509Store(StoreName.My);
store.Open(OpenFlags.ReadOnly);
X509Certificate2 cert = store.Certificates.Cast<X509Certificate2>().First(item => item.FriendlyName == certName);
HDInsightCertificateCredential creds = new HDInsightCertificateCredential(subscriptionId, cert);
IHDInsightClient client = HDInsightClient.Connect(creds);
var cluster = client.ListClusters();
var c = new List<ClusterList>();
foreach (var item in cluster)
{
c.Add(new ClusterList() { Name = item.Name });
c.Add(new ClusterList() { Node = item.ClusterSizeInNodes });
}
return View(c);
}
public async Task<ActionResult> Loggedin()
{
ViewBag.Message = "Your application description page.";
var c = new List<ClusterList>();
var call = Task.Factory.StartNew(() => c=GetAsync());
await call;
return View(c);
}
public List<ClusterList> GetAsync()
{
Guid subscriptionId = new Guid("your-subscription-id"); //your-subscription-id
string certName = "Friendly";//your-subscription-management-cert-name
// Create an HDInsight Client
X509Store store = new X509Store(StoreName.My);
store.Open(OpenFlags.ReadOnly);
X509Certificate2 cert = store.Certificates.Cast<X509Certificate2>().Single(item => item.FriendlyName == certName); //your friendly name
HDInsightCertificateCredential creds = new HDInsightCertificateCredential(subscriptionId, cert);
IHDInsightClient client = HDInsightClient.Connect(creds);
var cluster = client.ListClusters();
var c1 = new List<ClusterList>();
foreach(var item in cluster)
{
c1.Add(new ClusterList() { Name = item.Name, Node = item.ClusterSizeInNodes });
}
return c1;
}
public异步任务Loggedin()
{
ViewBag.Message=“您的应用程序描述页。”;
var c=新列表();
var call=Task.Factory.StartNew(()=>c=GetAsync());
等待电话;
返回视图(c);
}
公共列表GetAsync()
{
Guid subscriptionId=新Guid(“您的订阅id”);//您的订阅id
string certName=“Friendly”;//您的订阅管理证书名称
//创建HDInsight客户端
X509Store=新的X509Store(StoreName.My);
打开(OpenFlags.ReadOnly);
X509Certificate2 cert=store.Certificates.Cast().Single(item=>item.FriendlyName==certName);//您的友好名称
HDInsightCertificateCredential creds=新HDInsightCertificateCredential(订阅ID,证书);
IHDInsightClient=HDInsightClient.Connect(creds);
var cluster=client.ListClusters();
var c1=新列表();
foreach(集群中的var项)
{
添加(new ClusterList(){Name=item.Name,Node=item.ClusterSizeInNodes});
}
返回c1;
}
模型保持不变
看法
@型号列表
@{
ViewBag.Title=“Loggedin”;
Layout=“~/Views/Shared/_Layout.cshtml”;
}
洛格丁
@Html.Label(“名称”)
@Html.Label(“节点”)
@foreach(模型中的var项目)
{
@项目名称
@项目.节点
}
您的视图使用模型群集列表
,但您的控制器正在通过列表
?-这应该引发一个异常!我用@model List
替换了@model listCluster.Models.ClusterList
,即使这样,我也没有得到任何输出。页面一直在加载@Stephen Mueckeyor视图仍有其他错误将引发异常<代码>列表
不包含属性名称
或节点
-您需要一个循环来为集合中的每个集群列表
呈现一个表行。其他奇怪的事情包括为client.ListClusters()
返回的每个对象创建2个ClusterList
对象-一个带有Name
属性,另一个带有节点
属性。不确定你所说的页面持续加载是什么意思!-页面甚至不会开始加载,因为您应该看到异常(您是否甚至点击了返回视图(c);
行?)。是的,您是对的。事实上,我对所有这些概念都是全新的。我不知道要做什么改变。你能帮我更正一下密码吗。非常感谢。