我想实现用户必须登录才能看到网站内容

一匹野狼 2009-03-18 11:35:04
我现在就是想通过用户登录后才能看网站的某些内容。但我不知道怎么实现,请高手帮帮忙,还有就是登录后,把登录页面换成用户的基本信息页面,想请教怎么实现
...全文
430 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hhxxcj 2009-03-18
  • 打赏
  • 举报
回复
protected void Page_Load(object sender, EventArgs e)
{
if (!IsExitAdmin())
{
Response.Redirect("Login.aspx", true);
return;
}
}

/// <summary>
/// 判断用户是否已经登录
/// </summary>
/// <returns></returns>
public bool IsExitAdmin()
{
HttpCookieCollection col = Request.Cookies;
HttpCookie UserName = col["AdminID"];
bool bo = false;
if (Session["AdminID"] == null & (UserName == null || UserName.ToString() == ""))
bo = false;
else
{
if (UserName != null && UserName.ToString() == "")
{
Session["AdminID"] = UserName;
}
bo = true;
}
return bo;
}


这样就行了
深海之蓝 2009-03-18
  • 打赏
  • 举报
回复
来晚了,1楼的可以
candy_whut 2009-03-18
  • 打赏
  • 举报
回复
1.通过用户登录后才能看网站的其他界面
在登录界面:
//保存用户名和密码到Session里,为了检测以后的界面都是经过登录成功后才能打开,否则返回登录界面
Session["userid"] = UserInfo.UserID;
在其他界面加判断:
string UserID = Session["userid"] == null ? "" : Session["userid"].ToString();
if (string.IsNullOrEmpty(UserID))
{
Page.Response.Redirect("LogIn.aspx");
return;
}
2.登录后,把登录页面换成用户的基本信息页面
Page.Response.Redirect("***.aspx");
moonshineidolon 2009-03-18
  • 打赏
  • 举报
回复
举个例子 ,网站页面上登录后可以看到10个标签,登录前能看到3个。

你可以把其中8个设置成不可见

登录后让标签可见,点击标签才能看到每个页的内容

moonshineidolon 2009-03-18
  • 打赏
  • 举报
回复
用户登录后

respons里面有个重定向

就可以把页面跳转了

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧