使用会话在数据库中保存注销时间 [英] Save logout time in database using session

查看:137
本文介绍了使用会话在数据库中保存注销时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户在C#中使用会话点击退出按钮,如何在数据库中保存注销时间?

How to save logout time in database when user click on logout button using session in C#?

string username = Session["uname"].ToString();
           string password = Session["pwd"].ToString();
           lbl_1.Text = username;
               cn.Open();
               SqlCommand cmd = new SqlCommand();
               cmd.Connection = cn;
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.CommandText = "SP_TRACK_USE";
               cmd.Parameters.AddWithValue("@Username", username);
               cmd.Parameters.AddWithValue("@Password", password);
               cmd.Parameters.AddWithValue("@COMMAND", 1);
               cmd.ExecuteScalar();
               cn.Close();
               Response.Redirect("Default.aspx");



编码运行正常,但注销时间未保存在数据库中。


Coding runs properly, but logout time is not saved in database.

推荐答案

use SQL Server会话模式,用于存储和从系统中选择日期。



在ASP.NET中探索会话 [ ^ ]

希望它有所帮助!
use SQL Server Session mode to store and pick the date from the system.

Exploring Session in ASP.NET[^]
hope it helped!






为什么不用附加参数''logout_time''改变StoredProcedure并传递值

Hi,

why not you alter the StoredProcedure with additional parameter ''logout_time'' and pass the value
string username = Session["uname"].ToString();
            string password = Session["pwd"].ToString();
            lbl_1.Text = username;
                cn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = cn;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "SP_TRACK_USE";
                cmd.Parameters.AddWithValue("@Username", username);
                cmd.Parameters.AddWithValue("@Password", password);
                cmd.Parameters.AddWithValue("@logout_time", DateTime.Now());
                cmd.Parameters.AddWithValue("@COMMAND", 1);
                cmd.ExecuteScalar();
                cn.Close();
                Response.Redirect("Default.aspx");


您可以在 global.asax 文件中执行此操作。
You can do this in global.asax file.


这篇关于使用会话在数据库中保存注销时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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