私のアプリケーションでは、2人以上のユーザーがログインし、同時に(同じ時刻に)同じページをクリックするとログインします他人のログインによって変更されました。 ページロードイベントのコードは次のとおりです。2人以上のユーザーが同じページを同時にクリックすると、他のユーザーによってログインが変更される
MembershipUser mUser = Membership.GetUser();
if (mUser != null)
{
aspUserId.Value = mUser.ProviderUserKey.ToString();
DBHandler dbHandler = new DBHandler();
SqlCommand cmd = new SqlCommand();
cmd.Parameters.AddWithValue("@AspNetUserID", mUser.ProviderUserKey);
string sPMSUserId = dbHandler.GetSingleValue(cmd, "get_PMSUserId");
hdnUserID.Value = sPMSUserId;
}
else
{
Response.Redirect("~/index.aspx");
}
hdnUserIDは、値をsqlDatasourceのselect文パラメータに渡すために使用されます。 aspUserIdは、ユーザーのaspnet_UserIDをテストするためにも使用されます。私は検査要素 を使ってテストします。他のユーザーのaspnet_UserIDによって値が変更されています。 DBHandlerで
その
public string GetSingleValue(SqlCommand sqlcmdWithParameters, string CommandText)
{
string sReturn = "";
SqlConnection sqlcon = new SqlConnection(strconn);
sqlcmdWithParameters.Connection = sqlcon;
sqlcmdWithParameters.CommandType = CommandType.StoredProcedure;
sqlcmdWithParameters.CommandText = CommandText;
try
{
sqlcon.Open();
sReturn = Convert.ToString(sqlcmdWithParameters.ExecuteScalar());
}
catch (Exception ex)
{
sReturn = "-1";
}
finally
{
sqlcon.Close();
}
return sReturn;
}
最後に、私は、問題の原因を得たように私はコードで
string strconn = ConfigurationManager.ConnectionStrings["strconn"].ConnectionString;
などの接続文字列を使用していました。うん、それは私が
<%@ OutputCache Duration ="1" NoStore ="true" VaryByParam ="*" %>
これは1秒間キャッシュするために私のページを保つようOutputCacheのディレクティブを取る.aspxのページに起因するキャッシュ
にあります。他のページが1秒以内にリクエストを出した場合、そのページは他のユーザーであってもキャッシュに戻ります。
あなたの質問は何ですか? –
「正確な時刻」は正確にどのくらいですか?2台のコンピュータで同じ時刻にサーバーにログインするのは困難ですか? – Patrick