zoukankan
html css js c++ java
如何实现计数器
在
Global.asax.cs
文件中的分别输入以下代码:
protected
void
Application_Start(Object sender, EventArgs e)
{
SqlConnection con;
SqlCommand cmd;
//
Get the connection string from the existing key in Web.config
con
=
new
SqlConnection(ConfigurationSettings.AppSettings[
"
cnFriends.ConnectionString
"
]);
cmd
=
new
SqlCommand(
"
SELECT Visitors FROM Counter
"
, con);
con.Open();
protected
void
Session_Start(Object sender, EventArgs e)
{
Application.Lock();
Application[
"
counter
"
]
=
((
int
)Application[
"
counter
"
])
+
1
;
Application.UnLock();
}
try
{
//
Retrieve the counter
Application[
"
counter
"
]
=
(
int
) cmd.ExecuteScalar();
}
finally
{
con.Close();
}
}
protected
void
Application_AuthenticateRequest(Object sender, EventArgs e)
{
//
Cast the sender to the application
HttpApplication app
=
(HttpApplication)sender;
//
Only replace the context if it has already been handled
//
by forms authentication module (user is authenticated)
if
(app.Request.IsAuthenticated)
{
SqlConnection con;
string
sql;
SqlCommand cmd;
string
id
=
Context.User.Identity.Name;
con
=
new
SqlConnection(ConfigurationSettings.AppSettings[
"
cnFriends.ConnectionString
"
]);
sql
=
"
SELECT IsAdministrator FROM [User] WHERE UserId='{0}'
"
;
sql
=
String.Format(sql, id);
cmd
=
new
SqlCommand(sql, con);
con.Open();
//
Ensure closing the connection
try
{
object
admin
=
cmd.ExecuteScalar();
//
Was it a valid UserID?
if
(admin
!=
null
)
{
GenericPrincipal ppal;
string
[] roles;
//
If IsAdministrator field is true, add both roles
if
(((
bool
)admin)
==
true
)
{
roles
=
new
string
[]
{
"
User
"
,
"
Admin
"
}
;
}
else
{
roles
=
new
string
[]
{
"
User
"
}
;
}
ppal
=
new
GenericPrincipal(Context.User.Identity, roles);
Context.User
=
ppal;
}
else
{
//
If UserID was invalid, clear the context so he logs on again
Context.User
=
null
;
}
}
catch
{
throw
;
}
finally
{
con.Close();
}
}
}
protected
void
Application_End(Object sender, EventArgs e)
{
SqlConnection con;
SqlCommand cmd;
//
Get the connection string from the existing key in Web.config
con
=
new
SqlConnection(ConfigurationSettings.AppSettings[
"
cnFriends.ConnectionString
"
]);
cmd
=
new
SqlCommand(
"
UPDATE Counter SET Visitors=
"
+
Application[
"
counter
"
].ToString(), con);
con.Open();
try
{
cmd.ExecuteNonQuery();
}
finally
{
con.Close();
}
}
查看全文
相关阅读:
paper 89:视频图像去模糊常用处理方法
paper 88:人脸检测和识别的Web服务API
paper 87:行人检测资源(下)代码数据【转载,以后使用】
paper 86:行人检测资源(上)综述文献【转载,以后使用】
paper 85:机器统计学习方法——CART, Bagging, Random Forest, Boosting
paper 84:机器学习算法--随机森林
paper 83:前景检测算法_1(codebook和平均背景法)
paper 82:边缘检测的各种微分算子比较(Sobel,Robert,Prewitt,Laplacian,Canny)
paper 81:HDR成像技术
paper 80 :目标检测的图像特征提取之(一)HOG特征
原文地址:https://www.cnblogs.com/ahuang1118/p/172566.html
最新文章
不能访问windows installer 服务,可能你在安全模式下运行 windows ,或者windows installer
java将父类所有的属性COPY到子类中
Tomcat的几种部署方式
MySQL在Linux下的表名如何不区分大小写
Js封装html的一些代码
Jquery常用操作
IE和Firefox浏览器CSS兼容性技巧整理
asp.net c# 断点续传 下载 Accept-Ranges
NET(C#):使用HttpWebRequest头中的Range下载文件片段
CSV 文件读写
热门文章
c# HttpWebRequest与HttpWebResponse
cookie窃取和session劫持
C # Cookie
mvc 从客户端 中检测到有潜在危险的 Request 值
doctype声明、浏览器的标准、怪异等模式
C# 之 Request
paper 92:图像视觉博客资源2之MIT斯坦福CMU
paper 92:Lena与图像处理
paper 91:边缘检测近期最新进展的讨论
paper 90:人脸检测研究2015最新进展
Copyright © 2011-2022 走看看