asp.net只显示匿名用户的登录表单

时间:2014-05-14 11:59:06

标签: asp.net login

我的主页页眉中有一个登录表单,无论是登录还是退出,都会显示。如何将其更改为仅显示给匿名用户?

我试过这个

<asp:LoginView ID="Loginview1" runat="server">
    <AnonymousTemplate>
        <ul id="loginmeni">
            <ul>
                <asp:TextBox ID="txtusername" runat="server" placeholder="Username"></asp:TextBox></ul>
            <ul>
                <asp:TextBox ID="txtpassword" runat="server" placeholder="Password"></asp:TextBox></ul>
            <ul>
                <asp:Button ID="Button1" class="buttonlogin" runat="server" Text="Button" OnClick="Button1_Click" /></ul>
            <a href="#">Zaboravljena sifra</a>
        </ul>
    </AnonymousTemplate>
    <LoggedInTemplate>
        <a href="#">Logout</a>
    </LoggedInTemplate>
</asp:LoginView>

这是点击事件

protected void Button1_Click(object sender, EventArgs e)
{
    if(txtusername.Text !="" || txtpassword.Text !="")
    {

        Vlasnici v= ServisnaKlasa.VratiVlasnika(txtusername.Text.Trim(),txtpassword.Text.Trim());
        if(v !=null)
        {
            loginsesija.v = v;
            FormsAuthenticationTicket tiket = new FormsAuthenticationTicket(v.VlasnikID.ToString(), false, 30);
            string enTicket = FormsAuthentication.Encrypt(tiket);
            HttpCookie loginCookie = new HttpCookie(FormsAuthentication.FormsCookieName, enTicket);
            Response.Cookies.Add(loginCookie);
            Response.Redirect(FormsAuthentication.GetRedirectUrl(v.VlasnikID.ToString(),false));
        }
        else
        {
            txtusername.Text = "";
            Response.Write("jebiga");
        }
    }
}

尝试登录时出错

  

对象引用未设置为对象的实例。

现在它甚至不识别那些文本字段“txtusername”和“txtpassword”

继承错误

  

错误4当前上下文中不存在名称“txtusername”D:\ PeP Projekat \ Web dio \ WebApplication10 \ main.Master.cs 23 16 IS_VeterinarskaStanicaWebDio

0 个答案:

没有答案