我有一个asp.net mvc应用程序,其局部视图用于呈现用户配置文件名称
@{ Html.RenderAction("GetPropertiesForUser", "UserProfile"); }
@model Inspinia_MVC5_xx.Models.UserProfile
<div class="dropdown profile-element">
<span>
<img alt="image" class="img-circle" src="~/Images/profile_small.jpg" />
</span>
<a data-toggle="dropdown" class="dropdown-toggle" href="#">
<span class="clear">
<span class="block m-t-xs">
<strong class="font-bold">@Model.displayName</strong>
</span> <span class="text-muted text-xs block">Art Director <b class="caret"></b></span>
</span>
</a>
<ul class="dropdown-menu animated fadeInRight m-t-xs">
<li><a href="@Url.Action("Profile", "AppViews")">Profile</a></li>
<li><a href="@Url.Action("Contacts", "AppViews")">Contacts</a></li>
<li><a href="@Url.Action("Inbox", "Mailbox")">Mailbox</a></li>
<li class="divider"></li>
<li><a href="@Url.Action("Login", "Pages")">Logout</a></li>
</ul>
</div>
<div class="logo-element">
IN+
</div>
代码:
public class UserProfileController : Controller
{
public async Task<ActionResult> GetPropertiesForUser()
{
Uri serviceRoot = new Uri(SettingsHelper.AzureAdGraphApiEndPoint);
var token = await AppToken.GetAppTokenAsync();
ActiveDirectoryClient adClient = new ActiveDirectoryClient(
serviceRoot,
async () => await AppToken.GetAppTokenAsync());
string userObjectID = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
Microsoft.Azure.ActiveDirectory.GraphClient.Application app = (Microsoft.Azure.ActiveDirectory.GraphClient.Application)adClient.Applications.Where(
a => a.AppId == SettingsHelper.ClientId).ExecuteSingleAsync().Result;
if (app == null)
{
throw new ApplicationException("Unable to get a reference to application in Azure AD.");
}
string requestUrl = string.Format("https://graph.windows.net/{0}/users/{1}?api-version=1.5", SettingsHelper.Tenant,ClaimsPrincipal.Current.Identities.First().Name);
HttpClient hc = new HttpClient();
hc.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(
"Bearer", token);
HttpResponseMessage hrm = await hc.GetAsync(new Uri(requestUrl));
if (hrm.IsSuccessStatusCode)
{
UserProfile up = JsonConvert.DeserializeObject<UserProfile>(await hrm.Content.ReadAsStringAsync());
return PartialView(up);
//return View("GetPropertiesForUser", new UserProfile
//{
// DisplayName = up.displayName() //I am still missing here to get the display name only
//});
}
else
{
return View();
}
}
}
但是我收到此错误
HttpServerUtility.Execute在等待异步时被阻止 操作完成。描述:发生了未处理的异常 在执行当前Web请求期间。请查看 堆栈跟踪以获取有关错误及其位置的更多信息 起源于代码。
异常详细信息:System.InvalidOperationException: HttpServerUtility.Execute在等待异步时被阻塞 操作完成。
来源错误:
第4行:第5行:
第6行:@ { Html.RenderAction(&#34; GetPropertiesForUser&#34;,&#34; UserProfile&#34;);第7行:
第8行:
我该如何解决这个问题?