In the Global.asax
, within the method Session_Start()
do the encoding to write by SessionId
(Session.SessionID
), one log of information.
I’ll propose a way:
Create a database with the following layout:
CREATE TABLE [dbo].[Log](
[SessionId] [nvarchar](24) NOT NULL,
[SessionDataTime] [datetime] NOT NULL,
[ServerIP] [nvarchar](15) NOT NULL,
CONSTRAINT [PK_Log] PRIMARY KEY CLUSTERED
(
[SessionId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
within the method Session_Start()
:
protected void Session_Start()
{
string SessionId = Session.SessionID;
string ServerIp = Request.ServerVariables["REMOTE_ADDR"];
DateTime SessionDataTime = DateTime.Now;
using (SqlConnection Conn = new SqlConnection(@"Server=.\SQLExpress;Database=Db;User Id=sa;Password=senha;MultipleActiveResultSets=true;"))
using (SqlCommand Command = Conn.CreateCommand())
{
Conn.Open();
Command.CommandText = "SELECT COUNT(*) FROM Log WHERE SessionId=@SessionId";
Command.Parameters.Add("SessionId", SqlDbType.NVarChar, 24).Value = SessionId;
if (int.Parse(Command.ExecuteScalar().ToString()) == 0)
{
Command.Parameters.Clear();
Command.CommandText = "INSERT INTO Log (SessionId,ServerIp,SessionDataTime) VALUES(@SessionId,@ServerIp,@SessionDataTime)";
Command.Parameters.Add("SessionId", SqlDbType.NVarChar, 24).Value = SessionId;
Command.Parameters.Add("ServerIp", SqlDbType.NVarChar, 15).Value = ServerIp;
Command.Parameters.Add("SessionDataTime", SqlDbType.DateTime).Value = SessionDataTime;
Command.ExecuteNonQuery();
}
}
}
a new registration shall be entered only upon the renewal of its SessionId
.
http://answall.com/q/52240/101. Nothing specific, but neither is the question. Either it is duplicate or it seems broad.
– Maniero
Could you add more details? Does your site have login? It will count if you access any screen?
– Randrade
My site has no login, any screen account if it is the first time the site is accessed. if he accesses www.meusite.com.br then account if it is the first time, if he accesses direct www.meusite.com.br/Minhapagina then account if it is the first time
– Mauricio Ferraz
I don’t know how to identify if it’s the first time to record in the bank, that’s all I need. I’m seeing here what I might be able to do with Actionfilters, but how can I make an if by checking if it’s the customer’s first time on the site?
– Mauricio Ferraz