Asp.net mvc 3 自定义身份验证帮助器类。需要帮助吗

Asp.net mvc 3 自定义身份验证帮助器类。需要帮助吗,asp.net-mvc-3,Asp.net Mvc 3,我有一个helper方法,它只检查用户是否经过身份验证,但检查它的生成错误 助手方法 public static bool IsLoggedIn(this HtmlHelper helper) { return helper.ViewContext.HttpContext.Request.IsAuthenticated; } 查看 @if (GH.IsLoggedIn) //Error is on this line { <div class="

我有一个helper方法,它只检查用户是否经过身份验证,但检查它的生成错误

助手方法

public static bool IsLoggedIn(this HtmlHelper helper)
    {
        return helper.ViewContext.HttpContext.Request.IsAuthenticated;
    }
查看

@if (GH.IsLoggedIn) //Error is on this line
{ 
    <div class="sign-text" >Signed In As @GH.IdentityName </div>
}

有人告诉我问题出在哪里。

你为什么不这样称呼它
@if(Html.IsLoggedIn()){..}

您可能希望使此方法呈现适当的HTML,而不是在视图中执行
@if(…)
检查

public static MvcHtmlString SignInText(this HtmlHelper htmlHelper)
{
    // you code here
}
然后按以下方式将其插入视图:

@Html.SignInText()

谢谢我的愚蠢。你能告诉我如何在@Html.IsLoggedIn()上写这个三元语句吗?以@Html.IdentityName
@Html.Raw(Html.IsLoggedIn()?“以“+Html.Encode(Html.IdentityName)+”“:String.Empty”的身份登录”
是否希望我在您的SignInText的HtmlHelp中使用上述Singin链接。隐藏逻辑?
@Html.SignInText()