0
我有一个使用web表单和MVC的web应用程序。我有一个web表单的功能,工作正常。现在我想引用它的MVC控制器如何将Web窗体功能传递给MVC控制器?
这是我在网络表单中使用的功能:
public string getClaimValue()
{
string claimvalue = null;
var claimsId = Page.User.Identity as IClaimsIdentity;
if (claimsId != null)
{
var claims = claimsId.Claims;
foreach (var claim in claims)
{
string claimtype = claim.ClaimType.ToString();
int index = claimtype.IndexOf("MBUN");
if (index > 0)
{
claimvalue = claim.Value;
}
}
}
return claimvalue;
}
但是,当我把这个功能下MVC控制器,我得到了在“页面”红线说: '这个名字在当前的情况下不存在'。删除“网页”后,但我没有在网络表单中期望的值。 需要你的帮助。 谢谢。
+1良好的工作:
与更换。两者都很常见。 –
我之前尝试过,它不起作用。同样的功能,在网页形式中,我可以获得claimtype相等的'MBUN'。但在MVC中,如果我使用System.Web.HttpContext.Current.User.Identity作为claimid,我无法获得claimtype'MBUN'。我可以在Web窗体和MVC中找到不同的值,Web窗体中的计数值是4,但在MVC中是0。不知道为什么。 – howexg9
那么Page.User.Identity只是System.Web.HttpContext.Current.User.Identity的一个快捷方式。 看来你的webforms应用程序正确地设置了User.Identity对象(可能在页面的基类中),但它并没有在你的MVC控制器中设置。 –