怎么写判断用户是否登录
如图当我输入“朱洪涛的”时候,点击进入论坛就会弹出“欢迎朱洪涛会员”。
Default.aspx代码为
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="请输入会员名称:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="进入论坛" />
</div>
</form>
</body>
</html>
Default.aspx.csusing System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
/* protected void Page_Load(object sender, EventArgs e)
{
string mc = BS201102.DSQL.GetDataFieldBySearch("select mc from cs1");
BS201102.Other.MyControl.Alerts(mc);
}
* */
protected void Button1_Click(object sender, EventArgs e)
{
BS201102.Other.MyControl.Alerts("欢迎朱洪涛会员!");
}
}
--------------------编程问答-------------------- 定义个Session记着,我记得以前搞web就是这样记录的,需要判断是否登陆的时候,取一遍session的值 --------------------编程问答-------------------- 明显session,网上查下怎么存放session吧,一堆。。。 --------------------编程问答-------------------- 最简单的就是搞个变量存一下,最常用的就是使用Session、Cookie、Application或者使用Viewstate等等.. --------------------编程问答--------------------
Viewstate和Application明显不合适 --------------------编程问答-------------------- 取决于你如何进行authentication的。
参考
http://q.cnblogs.com/q/604/ --------------------编程问答-------------------- 强顶session --------------------编程问答-------------------- session那些是好用,但是有时会丢失哩…… --------------------编程问答-------------------- protected void Button1_Click(object sender, EventArgs e)
{
Session["Vip"]=this.TextBox1.Text.Trim();
BS201102.Other.MyControl.Alerts("欢迎朱洪涛会员!");
}
在其它页的Page_Load事件里写上:
if(Page.IsPostBack)
return;
if(Session["Vip"]==null||Session["Vip"].ToString()=="")
//跳转到登录页 --------------------编程问答-------------------- 或者在地址栏传值,然后判断Request["参数名"]是否为空 --------------------编程问答-------------------- 可以在用表中增加一个字段,比如"isLogin"来标记是否登录,平时就设置为false,登录后就设置为true
补充:.NET技术 , C#