首页 > 代码库 > 【原创】如何编写c#用户登陆后用户名在前台显示

【原创】如何编写c#用户登陆后用户名在前台显示

 

这种肯定是判断session啦!!!!!

@{
    string username = (string)Session["username"];
    user user = new user();
    if (username != null && username.Length > 0)
    {
        user = (user)Session["user"];
    }
}

  在页面中就这样写

   @{

    int isLogin = 0;
    if (username != null && username.Length > 0)
    {
        isLogin = 1;

        if (user.type == 1)
        {
            <span class="gr-title"><b></b>@username</span>
            <div class="sidemenu">
                <a href="http://www.mamicode.com/Fastorders/myFastorderList?userID=@user.id" class="">我的订单</a>
                <a href="http://www.mamicode.com/user/logout">退出当前帐号</a>
            </div>
        }
        else
        {
            <span class="gs-title"><b></b>@username</span>
            <div class="sidemenu">
                <a href="http://www.mamicode.com/Fastorders/myFastorderList?userID=@user.id" class="">单位订单</a>
                <a href="http://www.mamicode.com/user/logout">退出当前帐号</a>
            </div>
        }
    }
    else
    {
        <span style="padding-left: 30px;background: url(/images/index/index-login.png) no-repeat 5px center;"></span>
        <a href="http://www.mamicode.com/user/login" style="margin-right:15px;">登录</a><a href="http://www.mamicode.com/user/register">注册</a>
    }
}

  

【原创】如何编写c#用户登陆后用户名在前台显示