我有一个asp.net页面,在chrome& mozilla但是当我在safari或IE9中加载它时,页面会触发两次。当第二次触发页面时,会话变为空。我没有得到为什么safari& IE9两次触发页面。
我的代码如下: -
public partial class home : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
FBInstance fb;
if (!IsPostBack)
{
Drivertab(Convert.ToInt32(GlobalVars.DriverType.PAVEMENT));
Drivertab(Convert.ToInt32(GlobalVars.DriverType.OFFROAD));
if (Request.Form["signed_request"] != null)
{
string payload = Request.Params["signed_request"].Split('.')[1];
var encoding = new UTF8Encoding();
var decodedJson = payload.Replace("=", string.Empty).Replace('-', '+').Replace('_', '/');
var base64JsonArray = Convert.FromBase64String(decodedJson.PadRight(decodedJson.Length + (4 - decodedJson.Length % 4) % 4, '='));
var json = encoding.GetString(base64JsonArray);
//Response.Write(json.ToString());
var o = JObject.Parse(json);
var lPid = Convert.ToString(o.SelectToken("page.id")).Replace("\"", "");
var isLiked = Convert.ToString(o.SelectToken("page.liked")).Replace("\"", "");
var lUserId = Convert.ToString(o.SelectToken("user_id")).Replace("\"", "");
{
string message = string.Empty;
DataTable FBUserData = StoredProcedures.ReadFacebookUserID(lUserId, out message);
hfIsUserAuthenticated.Value = "false";
if (FBUserData != null)
{
if (FBUserData.Rows.Count > 0)
{
hfIsUserAuthenticated.Value = "true";
fb = new FBInstance();
fb.BUserID = Convert.ToInt32(FBUserData.Rows[0]["UserID"]);
fb.FBUserID = FBUserData.Rows[0]["FacebookUserID"].ToString();
fb.AuthToken = FBUserData.Rows[0]["AuthToken"].ToString();
fb.IsAuthenticated = Convert.ToBoolean(FBUserData.Rows[0]["IsActive"]);
fb.NoOfVote = 0;
Session[GlobalVars.FBSession] = fb;
hfFBUserID.Value = fb.FBUserID;
RecentVoteDriver(Convert.ToInt32(GlobalVars.DriverType.PAVEMENT), fb);
RecentVoteDriver(Convert.ToInt32(GlobalVars.DriverType.OFFROAD), fb);
}
}
}
}
}
}
protected void Drivertab(int driverTypeID)
{
DataTable dt = StoredProcedures.ReadDriverCard(driverTypeID);
if (driverTypeID == 1)
{
dtDriverCard.DataSource = dt;
dtDriverCard.DataBind();
}
else
{
dtDriverCard2.DataSource = dt;
dtDriverCard2.DataBind();
}
}
public void RecentVoteDriver(int DriverTypeID, FBInstance fb)
{
DataTable dt = StoredProcedures.ReadRecentVote(fb.BUserID, DriverTypeID);
if (DriverTypeID == 2)
{
if (dt.Rows.Count > 0)
{
DateTime VoteDate = Convert.ToDateTime(dt.Rows[0]["VoteDateTime"]);
if (VoteDate.Date != DateTime.Now.Date)
{
Image1.ImageUrl = GlobalVars.ImageURL + "/DefaultDriver.jpg";
}
else
{
DataTable Rdt = StoredProcedures.ReadRecentDriverCard(Convert.ToInt32(dt.Rows[0]["DriverCardID"]));
if (Rdt.Rows.Count > 0)
{
Image1.ImageUrl = GlobalVars.ImageURL + "/drivers/" + Rdt.Rows[0]["ImageURL"].ToString();
}
else
{
Image1.ImageUrl = GlobalVars.ImageURL + "/DefaultDriver.jpg";
}
}
}
else
{
Image1.ImageUrl = GlobalVars.ImageURL + "/DefaultDriver.jpg";
}
}
else
{
if (dt.Rows.Count > 0)
{
DateTime VoteDate = Convert.ToDateTime(dt.Rows[0]["VoteDateTime"]);
if (VoteDate.Date != DateTime.Now.Date)
{
Image2.ImageUrl = GlobalVars.ImageURL + "/DefaultDriver1.jpg";
}
else
{
DataTable Rdt = StoredProcedures.ReadRecentDriverCard(Convert.ToInt32(dt.Rows[0]["DriverCardID"]));
if (Rdt.Rows.Count > 0)
{
Image2.ImageUrl = GlobalVars.ImageURL + "/drivers/" + Rdt.Rows[0]["ImageURL"].ToString();
}
else
{
Image2.ImageUrl = GlobalVars.ImageURL + "/DefaultDriver1.jpg";
}
}
}
else
{
Image2.ImageUrl = GlobalVars.ImageURL + "/DefaultDriver1.jpg";
}
}
}
是否有人有任何解决方案。
感谢您的帮助
答案 0 :(得分:0)
public partial class home : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
FBInstance fb;
if (!IsPostBack)
{
Drivertab(Convert.ToInt32(GlobalVars.DriverType.PAVEMENT));
Drivertab(Convert.ToInt32(GlobalVars.DriverType.OFFROAD));
if (Request.Form["signed_request"] != null)
{
string payload = Request.Params["signed_request"].Split('.')[1];
var encoding = new UTF8Encoding();
var decodedJson = payload.Replace("=", string.Empty).Replace('-', '+').Replace('_', '/');
var base64JsonArray = Convert.FromBase64String(decodedJson.PadRight(decodedJson.Length + (4 - decodedJson.Length % 4) % 4, '='));
var json = encoding.GetString(base64JsonArray);
//Response.Write(json.ToString());
var o = JObject.Parse(json);
var lPid = Convert.ToString(o.SelectToken("page.id")).Replace("\"", "");
var isLiked = Convert.ToString(o.SelectToken("page.liked")).Replace("\"", "");
var lUserId = Convert.ToString(o.SelectToken("user_id")).Replace("\"", "");
{
string message = string.Empty;
DataTable FBUserData = StoredProcedures.ReadFacebookUserID(lUserId, out message);
hfIsUserAuthenticated.Value = "false";
if (FBUserData != null)
{
if (FBUserData.Rows.Count > 0)
{
hfIsUserAuthenticated.Value = "true";
fb = new FBInstance();
fb.BUserID = Convert.ToInt32(FBUserData.Rows[0]["UserID"]);
fb.FBUserID = FBUserData.Rows[0]["FacebookUserID"].ToString();
fb.AuthToken = FBUserData.Rows[0]["AuthToken"].ToString();
fb.IsAuthenticated = Convert.ToBoolean(FBUserData.Rows[0]["IsActive"]);
fb.NoOfVote = 0;
Session[GlobalVars.FBSession] = fb;
hfFBUserID.Value = fb.FBUserID;
RecentVoteDriver(Convert.ToInt32(GlobalVars.DriverType.PAVEMENT), fb);
RecentVoteDriver(Convert.ToInt32(GlobalVars.DriverType.OFFROAD), fb);
}
}
}
}
}
}
protected void Drivertab(int driverTypeID)
{
DataTable dt = StoredProcedures.ReadDriverCard(driverTypeID);
if (driverTypeID == 1)
{
dtDriverCard.DataSource = dt;
dtDriverCard.DataBind();
}
else
{
dtDriverCard2.DataSource = dt;
dtDriverCard2.DataBind();
}
}
public void RecentVoteDriver(int DriverTypeID, FBInstance fb)
{
DataTable dt = StoredProcedures.ReadRecentVote(fb.BUserID, DriverTypeID);
if (DriverTypeID == 2)
{
if (dt.Rows.Count > 0)
{
DateTime VoteDate = Convert.ToDateTime(dt.Rows[0]["VoteDateTime"]);
if (VoteDate.Date != DateTime.Now.Date)
{
Image1.ImageUrl = GlobalVars.ImageURL + "/DefaultDriver.jpg";
}
else
{
DataTable Rdt = StoredProcedures.ReadRecentDriverCard(Convert.ToInt32(dt.Rows[0]["DriverCardID"]));
if (Rdt.Rows.Count > 0)
{
Image1.ImageUrl = GlobalVars.ImageURL + "/drivers/" + Rdt.Rows[0]["ImageURL"].ToString();
}
else
{
Image1.ImageUrl = GlobalVars.ImageURL + "/DefaultDriver.jpg";
}
}
}
else
{
Image1.ImageUrl = GlobalVars.ImageURL + "/DefaultDriver.jpg";
}
}
else
{
if (dt.Rows.Count > 0)
{
DateTime VoteDate = Convert.ToDateTime(dt.Rows[0]["VoteDateTime"]);
if (VoteDate.Date != DateTime.Now.Date)
{
Image2.ImageUrl = GlobalVars.ImageURL + "/DefaultDriver1.jpg";
}
else
{
DataTable Rdt = StoredProcedures.ReadRecentDriverCard(Convert.ToInt32(dt.Rows[0]["DriverCardID"]));
if (Rdt.Rows.Count > 0)
{
Image2.ImageUrl = GlobalVars.ImageURL + "/drivers/" + Rdt.Rows[0]["ImageURL"].ToString();
}
else
{
Image2.ImageUrl = GlobalVars.ImageURL + "/DefaultDriver1.jpg";
}
}
}
else
{
Image2.ImageUrl = GlobalVars.ImageURL + "/DefaultDriver1.jpg";
}
}
}
答案 1 :(得分:0)
尝试编辑RecentVoteDriver
为Image1.ImageUrl
设置此默认值(可能会发生在某些情况下if-else子句中没有设置任何图像吗?)。
请查看页面上呈现的html:
每次出现
<img src=""/>
对于某些浏览器,可能会发生双重回发......
如果这是麻烦,您可以解决此问题,为每个按钮设置默认的空白图像
<asp:ImageButton ImageUrl="~/Images/blank.gif"...