在我的应用程序中,点击菜单" MyAccount(它将导航到agentadmin.cs文件)"我将会话超时。我已将会话时间设置为" 360"我也无法每次都能找到会议,有时它会显示出来。
方案是,如果您在“快速报价”屏幕(getquote.aspx)上等待一两分钟,然后尝试单击“我的帐户”,它可能会导致问题并显示“您必须登录...”屏幕。< / p>
MyParentBase.cs
public class MyParentBase : System.Web.UI.Page
{
public MyParentBase()
{
//
// TODO: Add constructor logic here
//
}
protected void Page_Error(object sender, EventArgs e)
{
Exception exp = Server.GetLastError();
new CustomErrors(exp);
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
//Check the User Objec in the Session
//If User object does not exist in the Session then Redirect to the Login Page..
if (Session["User"] == null)
{
Session.RemoveAll();
Session.Abandon();
HttpContext.Current.Response.Redirect("loginmessage.aspx", false);
//Response.Redirect("Index.aspx", false);
Response.End();
//ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "clientScript", "alert('Invalid Agent ID or Password')", true);
}
}
public void SetSecureProtocol(bool IsSecure)
{
string redirectURl = null;
if (HttpContext.Current.Request != null)
{
if (IsSecure && !HttpContext.Current.Request.IsSecureConnection)
{
redirectURl = HttpContext.Current.Request.Url.ToString().Replace("http:", "https:");
}
else if (!IsSecure && HttpContext.Current.Request.IsSecureConnection)
{
redirectURl = HttpContext.Current.Request.Url.ToString().Replace("https:", "http:");
}
if (redirectURl != null)
{
HttpContext.Current.Response.Redirect(redirectURl);
}
}
}
public void RedirectFromLogin()
{
if (HttpContext.Current.Session["User"] == null)
{
Session.RemoveAll();
Session.Abandon();
HttpContext.Current.Response.Redirect("loginmessage.aspx", false);
//HttpContext.Current.Response.Redirect("Index.aspx", false);
HttpContext.Current.Response.End();
//ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "clientScript", "alert('Invalid Agent ID or Password')", true);
}
}
}
AgentAdmin.aspx.cs
public partial class AgentAdmin : MyParentBase
{
string ErrorMsg = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
if (Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["Environment"]) == "Site")
{
SetSecureProtocol(true);
}
#region Bind AgentAdmin Style Sheet
HtmlLink cssLink = new HtmlLink();
cssLink.Href = "../Css/agentadmin.css";
cssLink.Attributes.Add("rel", "stylesheet");
cssLink.Attributes.Add("type", "text/css");
Header.Controls.Add(cssLink);
#endregion
if (!Page.IsPostBack)
{
try
{
BindAgentData();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}
public void BindAgentData()
{
# region Bind the data from Agent table
try
{
if (Convert.ToString((((Agent)(Session["User"])).AgentBusinessName)) != "")
lblBusiinessName.Text = Convert.ToString((((Agent)(Session["User"])).AgentBusinessName));
else
lblBusiinessName.Text = "";
if (Convert.ToString((((Agent)(Session["User"])).AgentFirstName)) != "")
lblFirstName.Text = Convert.ToString((((Agent)(Session["User"])).AgentFirstName));
else
lblFirstName.Text = "";
if (Convert.ToString((((Agent)(Session["User"])).AgentLastName)) != "")
lblLastName.Text = Convert.ToString((((Agent)(Session["User"])).AgentLastName));
else
lblLastName.Text = "";
if (Convert.ToString((((Agent)(Session["User"])).AgentAddress)) != "")
lblAdress.Text = Convert.ToString((((Agent)(Session["User"])).AgentAddress));
else
lblAdress.Text = "";
if (Convert.ToString((((Agent)(Session["User"])).AgentCity)) != "")
lblCity.Text = Convert.ToString((((Agent)(Session["User"])).AgentCity));
else
lblCity.Text = "";
if (Convert.ToString((((Agent)(Session["User"])).AgentStateID)) != "")
lblState.Text = Convert.ToString((((Agent)(Session["User"])).AgentStateID));
else
lblState.Text = "";
if (Convert.ToString((((Agent)(Session["User"])).AgentZipCode)) != "")
lblZipcode.Text = Convert.ToString((((Agent)(Session["User"])).AgentZipCode));
else
lblZipcode.Text = "";
if (Convert.ToString((((Agent)(Session["User"])).AgentPhoneNumber)) != "")
lblPhone.Text = Convert.ToString((((Agent)(Session["User"])).AgentPhoneNumber));
else
lblPhone.Text = "";
if (Convert.ToString((((Agent)(Session["User"])).AgentFaxNumber)) != "")
lblFax.Text = Convert.ToString((((Agent)(Session["User"])).AgentFaxNumber));
else
lblFax.Text = "";
if (Convert.ToString((((Agent)(Session["User"])).AgentEmail)) != "")
lblEmail.Text = Convert.ToString((((Agent)(Session["User"])).AgentEmail));
else
lblEmail.Text = "";
if (Convert.ToString((((Agent)(Session["User"])).AgentFedIDSS)) != "")
lblFederal.Text = Convert.ToString((((Agent)(Session["User"])).AgentFedIDSS));
else
lblFederal.Text = "";
if (Convert.ToString((((Agent)(Session["User"])).AgentUserName)) != "")
lblUserName.Text = Convert.ToString((((Agent)(Session["User"])).AgentUserName));
else
lblUserName.Text = "";
if (Convert.ToString((((Agent)(Session["User"])).AgentPass)) != "")
lblPassword.Text = "*******";
else
lblPassword.Text = "";
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
# endregion
}
protected void lbtnAgree_Onclick(object Sender, EventArgs e)
{
//print the AgentAgreement pdf by gselvam
try
{
#region print the AgentAgreement pdf using Itextsharp
int AgentId = 0;
if (Convert.ToString((((Agent)(Session["User"])).AgentID)) != "")
AgentId = Convert.ToInt32((((Agent)(Session["User"])).AgentID));
Agent AgentVar = new Agent();
AgentVar.AgentID = Convert.ToInt32(AgentId);
UserBobj UserBobjVar = new UserBobj(AgentVar);
AgentVar = UserBobjVar.LoadAgentByPrimaryKey();
string FileName = "AgentAgreement_";
if (AgentVar.AgentBusinessName != "")
{
FileName = "AgentAgreement_" + AgentVar.AgentBusinessName;
}
else if (AgentVar.AgentFirstName != "" && AgentVar.AgentFirstName != null)
{
FileName = "AgentAgreement_" + AgentVar.AgentFirstName + AgentVar.AgentLastName;
}
string AgentBusinessOrFL = string.Empty;
if (AgentVar.AgentBusinessName != "" && AgentVar.AgentBusinessName != null)
{
AgentBusinessOrFL = Convert.ToString(AgentVar.AgentBusinessName);
}
else
{
if (AgentVar.AgentFirstName != "" && AgentVar.AgentFirstName != null)
AgentBusinessOrFL = Convert.ToString(AgentVar.AgentFirstName).Trim() + " ";
else
AgentBusinessOrFL = "" + " ";
if (AgentVar.AgentLastName != "" && AgentVar.AgentLastName != null)
AgentBusinessOrFL += Convert.ToString(AgentVar.AgentLastName).Trim();
else
AgentBusinessOrFL += "";
}
string AgentAddress = string.Empty;
if (AgentVar.AgentAddress != "" && AgentVar.AgentAddress != null)
AgentAddress = Convert.ToString(AgentVar.AgentAddress);
else
AgentAddress = " ";
string AgentCityStateZip = string.Empty;
if (AgentVar.AgentCity != "" && AgentVar.AgentCity != null)
AgentCityStateZip = Convert.ToString(AgentVar.AgentCity) + ", ";
else
AgentCityStateZip = " " + ", ";
if (AgentVar.AgentStateID != "" && AgentVar.AgentStateID != null)
AgentCityStateZip += Convert.ToString(AgentVar.AgentStateID) + " ";
else
AgentCityStateZip += " " + " ";
if (AgentVar.AgentZipCode != "" && AgentVar.AgentZipCode != null)
AgentCityStateZip += Convert.ToString(AgentVar.AgentZipCode);
else
AgentCityStateZip += " ";
string AgentBusinessName = string.Empty;
if (AgentVar.AgentBusinessName != "" && AgentVar.AgentBusinessName != null)
AgentBusinessName = Convert.ToString(AgentVar.AgentBusinessName);
else
AgentBusinessName = " ";
string AgentName = string.Empty;
if (AgentVar.AgentFirstName != "" && AgentVar.AgentFirstName != null)
AgentName = Convert.ToString(AgentVar.AgentFirstName).Trim() + " ";
else
AgentName = "" + " ";
if (AgentVar.AgentLastName != "" && AgentVar.AgentLastName != null)
AgentName += Convert.ToString(AgentVar.AgentLastName).Trim();
else
AgentName += "";
string Inputfile = "~/InputPdf/AutoWarrantyAgentAgreement.pdf";
Inputfile = Server.MapPath(Inputfile);
string Outputfile = string.Empty;
Com.Thylak.CommonMethods.CommonMethods CommonMethodsVar = new Com.Thylak.CommonMethods.CommonMethods();
string MentionAnUser = CommonMethodsVar.LoadUserIdByUserInterface();
Outputfile = Server.MapPath("~/Output/") + FileName + MentionAnUser + ".pdf";
PdfReader reader = new PdfReader(Inputfile);
int n = reader.NumberOfPages;
PdfStamper stamper = new PdfStamper(reader, new FileStream(Outputfile, FileMode.Create));
AcroFields fields = stamper.AcroFields;
fields.SetField("PDF_DateEntered", String.Format("{0:MM/dd/yy}", AgentVar.AgentDateEntered));
fields.SetField("PDF_AgentBusinessName", AgentBusinessOrFL);
fields.SetField("PDF_AgentAddress", AgentAddress);
fields.SetField("PDF_AgentCityStateZip", AgentCityStateZip);
fields.SetField("PDF_DateEntered", String.Format("{0:MM/dd/yy}", AgentVar.AgentDateEntered));
fields.SetField("PDF_AgentBusinessName", AgentBusinessOrFL);
fields.SetField("PDF_AgentName", AgentName);
fields.SetField("PDF_DateEntered", String.Format("{0:MM/dd/yy}", AgentVar.AgentDateEntered));
stamper.FormFlattening = true;
stamper.Close();
//string filepath = Outputfile;
string filename = FileName;
string filepath = "~/Output/" + FileName + MentionAnUser + ".pdf";
Application["Path"] = filepath;
if ((File.Exists(Server.MapPath(filepath))))
{
string PageURl = "AutoWarrantyAgencyPDF.aspx";
string popupScript = "<script language='javascript'>" +
"window.open('" + PageURl + "', 'popup','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=800,height=500,left=100,top=100');" +
"</script>";
Page.RegisterStartupScript("PopupScript", popupScript);
}
//if (File.Exists(imag_path))
//{
// PdfBobj f_down = new PdfBobj(filename);
// string type = f_down.Downloader();
// Response.AppendHeader("content-disposition", "attachment; filename=" + filename);
// if (type != "")
// {
// Response.ContentType = type;
// }
// Response.WriteFile(imag_path, true);
// Response.Flush();
// FileInfo FileDel = new FileInfo(imag_path);
// FileDel.Delete();
// Response.End();
//}
#endregion
}
catch (Exception ex)
{
ErrorMsg = "An Error occured while processing your request : ";
Page.ClientScript.RegisterStartupScript(
typeof(AgentAdmin), "ERROR_DIALOG",
string.Format("alert('{0}');", ErrorMsg), true);
}
}
protected void lbEdit_Onclick(object Sender, EventArgs e)
{
Response.Redirect("EditAgentAdmin.aspx", false);
}
}