一种是根据参数做重定向处理,重定项时把T_equ参数清空掉处理,另一种是主页面传过来菜单码和guid在弹出页面做记录,如果文件中存在这个菜单码和guid时就当做是刷新页面处理不让页面处于新增状态,如果没找到的话就让页面处于新增状态并向文件中写入记录mc和guid.
(1)第一种方案:
bool isKeyFound = false; // Vital to stop calling recursively
string newQueryString = GetNewQueryString(Request.QueryString, "Refresh", out isKeyFound);
if (isKeyFound && newQueryString.Length > 0)
{
Response.Redirect(Request.Path + "?" + newQueryString);
}
{
string returnVal = string.Empty;
isKeyFound = false;
//Build the new query string.
for (int j = 0; j < queryString.Count; j++)
{
// Anything except the target key
if (j!=3&&!queryString.GetKey(j).ToLower().Equals(removeKey.ToLower()))
{
returnVal += queryString.GetKey(j) + "=" + queryString.Get(j) + "&";
}
else
{
if (j != 3)
{
isKeyFound = true;
}
}
}
//Remove the trailing '&'
return returnVal.TrimEnd('&');
}
(2)第二中方案:
tequ = Request.QueryString["T_equ"] != null ? Request.QueryString["T_equ"].ToString() : string.Empty;
mc = Request.QueryString["mc"] != null ? Request.QueryString["mc"].ToString() : string.Empty;
guid = Request.QueryString["Guid"] != null ? Request.QueryString["Guid"].ToString() : string.Empty;
bool isKeyFound = false;
if (!String.IsNullOrEmpty(mc) && !String.IsNullOrEmpty(guid))
{
ReadFile(mc, guid,out isKeyFound);
if (!String.IsNullOrEmpty(tequ) && !isKeyFound)
{
AddLoadExcuteScript("SetDefaultAddStatus();");
WgSemUse.StrFunAfterClientInitSelect = "SetDefaultAddStatus";
WriteFile(mc + "," +guid+",");
}
}
/// <summary>
/// 根据mc和guid读取文件
/// </summary>
/// <param name="mc"></param>
/// <param name="guid"></param>
/// <param name="isKeyFound"></param>
public void ReadFile(string mc, string guid, out bool isKeyFound)
{
string curr = HttpContext.Current.Request.PhysicalApplicationPath + "Document\\SemUseCertificateInfoUrl.txt";
isKeyFound = false;
if (File.Exists(curr))
{
FileStream fs = new FileStream(curr, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
StreamReader tr = new StreamReader(curr, System.Text.Encoding.Default);
tr.BaseStream.Seek(0, SeekOrigin.Begin);
string strLine = tr.ReadToEnd().Trim();
string[] temp = strLine.Split(',');
if (temp.Length > 0)
{
for (int i = 0; i < temp.Length; i++)
{
if (temp[i] == mc)
{
continue;
}
if (temp[i] == guid)
{
isKeyFound = true;
break;
}
}
}
tr.Close();
tr.Dispose();
}
/// <summary>
/// 写入文件
/// </summary>
/// <param name="data"></param>
public void WriteFile(string data)
{
string curr = HttpContext.Current.Request.PhysicalApplicationPath + "Document\\SemUseCertificateInfoUrl.txt";
bool isexist= File.Exists(curr);
if (isexist)
{
//StreamWriter streamw = File.AppendText(@"" + HttpContext.Current.Request.PhysicalApplicationPath + "/SemUseCertificateInfoUrl.txt");
StreamWriter streamw = File.AppendText(curr);
streamw.WriteLine(data);
streamw.Close();
streamw.Dispose();
}
else
{
File.Create(curr).Close();
}