***哪位大哥给段代码实现login.aspx?ReturnUrl=default.aspx

forliu 2003-07-23 03:36:11
意思是在站内任何页面,调用验证函数,如果是非法用户则转向登录首页,同时记录访问的目的页面,在登录后自动返回!
...全文
261 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
childeliu 2003-07-24
  • 打赏
  • 举报
回复
短消息中讨论一下!
forliu 2003-07-24
  • 打赏
  • 举报
回复
truesight(快乐鼠标)的做法还是不错的
大家还有详细的或者其他的方法吗?
imimp 2003-07-23
  • 打赏
  • 举报
回复
在web.config里面设置
<authentication mode="Forms">
<forms name="yourname" loginUrl="Login.aspx" protection="All" timeout="10" path="/"/>
</authentication>

<location path="Default.aspx">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
minajo21 2003-07-23
  • 打赏
  • 举报
回复
using System;
using System.Data;
using System.Data.SqlClient;

namespace BBS
{
public class BBSServer
{
private string m_strCon;
private SqlConnection m_Con;

//the property of connection string
public string ConnectString
{
get
{
return m_strCon;
}
set
{
m_strCon = value;
}
}
//connect 2 database
public void Connect2DB()
{
m_Con = new SqlConnection(m_strCon);
m_Con.Open();
}
//Log Into the BBS
public bool Login(string USER,string PSD)
{
USER.TrimEnd();
PSD.TrimEnd();
string strSqlLogIn = "Select Count(*) as uCount from webuser where name ='" + USER + "' and psd ='" + PSD + "'";
SqlCommand cmdLogIn = new SqlCommand(strSqlLogIn,m_Con);
int count =(int) cmdLogIn.ExecuteScalar();
if (count == 0)
return false;
else
return true;
}
}
}
truesight 2003-07-23
  • 打赏
  • 举报
回复
假设登录页是login.aspx
目标页是target.aspx
判断是否合法的函数IsLogined(username,password),合法返回true
用于存储是否登录的Session为Session["Logined"]
在target.aspx.cs中的Page_Load事件中
if(!Page.IsPostBack)
{
if((bool)Session["Logined"]==true){
}
else
{
Response.Redirect("login.aspx?go=target.aspx");
}
}
在login.aspx中
if(IsLogined(username,password)==true){

Session["Logined"]=true;
Response.Redirect(Request["go"].ToString());
}


思路是这样的,还有好多细节,如判断Request["go"]是否为Null等

111,098

社区成员

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

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

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