我需要逻辑来检查用户是否登录? [英] I need the logic to check whether the user is login ?

查看:58
本文介绍了我需要逻辑来检查用户是否登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在开发一个婚姻网站。



目前我没有设定蚂蚁标准。谁曾经访问我的页面他/她可以看到所有可用的配置文件。





实际上现在我想要的是,一旦用户跳进网站,他最初只能看到50个配置文件。如果他在达到50之后点击下一个按钮,它应检查用户是否已登录,如果他已登录,则应将他带到下一页,否则应该说请登录。



有谁可以帮我实现这个目标?





Hi i'm developing an Matrimony Website.

At Present i didn't set ant criteria.Who ever visit my page he/she can see all the available profiles.


Actually now what i want is,once the the user is jump into the site he can see only 50 profiles initially.if he click the next button after reach 50 it should check whether the user is logged in if he has logged in it should takes him to next page else it should say as "please login".

Can anyone help me to achieve this?


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;


public partial class brideview : System.Web.UI.Page
{
    
    string cmd;
    int pos;
    string gender, from, to, religion,category;
    protected void Page_Load(object sender, EventArgs e)
    {
        gender = Request.QueryString["Gender"].ToString();
        from = Request.QueryString["from"].ToString();
        to = Request.QueryString["to"].ToString();
        religion = Request.QueryString["religion"].ToString();
        category = Request.QueryString["category"].ToString();
        if (!IsPostBack)
        {
            ViewState["vs"] = 0;
        }
        pos = (int)this.ViewState["vs"];
        listing();

    }
    void listing()
    {
        try
        {
            cmd = "select distinct r.id,r.name,r.age,'~/TB_Photos/'+[PhotoName] as Url, '~/Photos/'+[PhotoName] as ImageFullUrl,r.Religion,r.landline,r.e_mail,r.country,p.education,p.income,p.occupation from registration r inner join profession p on p.id=r.id where Gender='" + gender + "' and status='active'";
            if (from.ToString() != "--Select--" && to.ToString() != "--Select--")
            {
                cmd = cmd + " and age between " + Convert.ToInt32(from) + " and " + Convert.ToInt32(to);
            }
            if (religion.ToString() != "--Select--")
            {
                cmd = cmd + " and religion='" + religion + "'";
            }
            if (category.ToString() != "--Select--")
            {
                cmd = cmd + " and occupation='" + category + "'";
            }
            cmd = cmd + " order by id desc";
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ToString());
            con.Open();
            SqlDataAdapter dadapter;
            dadapter = new SqlDataAdapter(cmd, con);
            DataSet dset = new DataSet();
            PagedDataSource adsource = new PagedDataSource();
            dadapter.Fill(dset);
            adsource.DataSource = dset.Tables[0].DefaultView;
            adsource.PageSize = 50;
            adsource.AllowPaging = true;
            adsource.CurrentPageIndex = pos;
            lbtnPrev.Enabled = !adsource.IsFirstPage;
            lbtnNext.Enabled = !adsource.IsLastPage;
            DataList1.DataSource = adsource;
            DataList1.DataBind();

            con.Close();
            con.Dispose();

        }
        catch (Exception ex)
        {

            //Response.Write(ex.Message);
        }
    }
    protected void lbtnPrev_Click(object sender, EventArgs e)
    {
        pos = (int)this.ViewState["vs"];
        pos -= 1;
        this.ViewState["vs"] = pos;
        listing();
    }
    protected void lbtnNext_Click(object sender, EventArgs e)
    {
        if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
        {
            pos = (int)this.ViewState["vs"];
            pos += 1;
            this.ViewState["vs"] = pos;
            listing();
        }
    }
}





这是我的代码...



当我点击



This is my code...

when i click

lbtnNext_Click

它应该验证用户是否已登录?

是否有任何例如:用于使用会话。



我不知道如何以及在哪里使用会话:(





提前谢谢。

it should verify that the user is logged in or not?
is there any eg: for using session.

I dont know how and where to use session :(


Thanks in advance.

推荐答案

你应该使用session。
You should use session for this.


hi the following代码对我有用:



hi the Following code works for me:

if (Session["UserAuthentication"] != null)
        {
            pos = (int)this.ViewState["vs"];
            pos += 1;
            this.ViewState["vs"] = pos;
            listing();
        }
        else
        {
            Response.Write("Please login to view more details");
            Response.Redirect("Login.aspx");
        }


这篇关于我需要逻辑来检查用户是否登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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