将登录链接更改为用户名,然后将注册者链接更改为在asp.net中注销 [英] Change the login link to the username and make the regiser link to logout in asp.net

查看:90
本文介绍了将登录链接更改为用户名,然后将注册者链接更改为在asp.net中注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个网站,因为我想将母版页的登录标签更改为已登录的用户名,并且注册链接应更改为注销,并且当我单击注销链接时,它应结束会话并进行更改默认登录的链接并再次注册....
我要在其中更改链接的母版页面
Master.master

i am making a website in that i want to change the login label of the master page to the username who has logged in and the register link should change to logout and when i click on logout link it should end the session and change the links to default login and register again....
Master page in which i want to change the links
Master.master

<table class="auto-style1">
            <tr>
               
                <td class="auto-style2"><a href="Signin.aspx" class="auto-style9" ><span class="auto-style5" id="signup2">Sign Up</span></a></td>
                <td><a href="Register.aspx" class="auto-style9"><span class="auto-style5">Register</span></a></td>
          </tr>
        </table


登录页面


Signin page

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;



public partial   class Signup : System.Web.UI.Page
{
    bool flag = false;

    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    public void Signin()
    {
        string login = txtlogin.Text;
        SqlCommand com;
        SqlDataReader dr;
        SqlConnection con = new SqlConnection();
        con.ConnectionString = ConfigurationManager.ConnectionStrings["Carzz"].ToString();
        con.Open();
        com = new SqlCommand("select RPassword from Registeration where REmail_id='" + login + "'", con);
        dr = com.ExecuteReader();
        if (!dr.Read())
        {
            Response.Write("<script>alert('Invalid User')</script>");
        }
        else
        {
            if (dr[0].ToString() == txtpass.Text)
            {
                Session["Username"] = login;
                flag = true;
                Response.Redirect("~/Home.aspx");
                
                
            }
            else
            {
                Response.Write("<script>alert('Invalid Username or Password')</script>");
                txtpass.Focus();
    }
        }
    }
        
    protected void btnsignin_Click(object sender, EventArgs e)
    {
        Signin();
        

            }

        }

推荐答案

创建4个链接,分别为登录,注销,注册和用户名.登录用户后,即会话处于活动状态,隐藏两个链接,进行登录和注册,并显示其他两个链接.
如果您发现会话处于非活动状态.隐藏这两个并显示其他.
create 4 links login, logout, register and username. Once you have logged in user i.e session is active hide the two links login and register and show other two.
If you find session inactive. hide these two and show other.



我想如果登录详细信息匹配,您将重定向到Home.aspx.所以我的建议是对home.apsx.put上的页面加载进行以下代码更改.


i guess you redirect to the Home.aspx if the login details matches. so my suggestion is to do changes from page load on home.apsx.put following code.

protected void Page_Load(object sender, EventArgs e)
       {

        // this will set the username to login
        ((Label)Master.FindControl("signup2")).Text = Session["Username"].ToString();

       }



使用该代码,您可以访问母版页的控件.但是我的建议是要有单独的链接来登录和注销.您可以根据需要显示或隐藏它们.

谢谢.希望对您有所帮助.



using that code you can access master pages''s controls. But my suggestion is to have separate links to Login Log out and register. you can show or hide them as it needed.

thanks. hope this helps.


这篇关于将登录链接更改为用户名,然后将注册者链接更改为在asp.net中注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆