views:

35

answers:

1

Could somebody please help me? We are developing a asp.net application using asp.net 2.0 framework. The issue is sporadic. As soon as a particular user hits the site in production a custom error page is shown. I been told that this user could get in successfully some times and after some idle time he is getting this error page. We not even not yet log in to site. Just as soon as i hit the site Ex:- www.Mywebsite.com the custom error is dispalyed. Could somebody help me on this. One more thing i have on my local machine .net 3.5 service pack1 installed and in production on only once server the service pack is installed. Could this be the cause of the problem?. some times it is showing the page and some users custom error. They not even visited the login screen yet. As soon as some users hit the site they see the customer error page, instead of login page. As i told this is happening as the user hitting the site I started checking my load code of index.aspx (page set up in virtual directories documents as start up page) and this is the code i am using.

My each .aspx page is inheriting the PageBase class which has the below method overriden and with the below code. If you see carefully the expiration of "langCookie" been given as 30 minutes. Will this be a problem? Below is a little code of my PageBase and my index.aspx. I am not sure what user's are doing. I heard it comes sporadically, so became hard to reproduce. One more thing since this is mix of asp and aspx pages i used below in web.config, Otherwise i am gettinig the sqaure characters in classic asp pages when i open them.

PageBase.cs Code:-

protected override void InitializeCulture()
    {
        base.InitializeCulture();


        HttpCookie langCookie = null;

        if (null == Request.Cookies[SESSION_KEY_LANGUAGE])
        {
            foreach (string s in Request.Cookies)
            {
                if (HttpUtility.UrlDecode(Request.Cookies[s].Name) == SESSION_KEY_LANGUAGE)
                {
                    langCookie = new HttpCookie(SESSION_KEY_LANGUAGE);
                    langCookie.Value = HttpUtility.UrlDecode(Request.Cookies[s].Value);                         langCookie.Expires = DateTime.Now.AddMinutes(30.0);
                    Response.Cookies.Add(langCookie);
                    break;
                }
            }
        }
        else
        {
            langCookie = Request.Cookies[SESSION_KEY_LANGUAGE];
        }

        if (null != langCookie)
        {
            if (langCookie.Value != "")
            {
                CultureInfo cultureInfo = new CultureInfo(langCookie.Value);
                ApplyNewLanguage(cultureInfo);
            }
        }
    }

index.aspx.cs:- The starting page in virtual is set as index.aspx

protected void Page_Load(object sender, EventArgs e)
{
        //Set sign button as default button for login (press enter)
        Page.Form.DefaultButton = "ButtonSignIn";

        //Get Cookie Language
        if (null == Request.Cookies[SESSION_KEY_LANGUAGE])
        {
            cookie = new HttpCookie(SESSION_KEY_LANGUAGE);
        }
        else
        {
            cookie = Request.Cookies[SESSION_KEY_LANGUAGE];
        }


        if (null == Request.Cookies[SESSION_KEY_LANGUAGE_FORASP])
        {
            cookieASP = new HttpCookie(SESSION_KEY_LANGUAGE_FORASP);
        }
        else
        {
            cookieASP = Request.Cookies[SESSION_KEY_LANGUAGE_FORASP];
        }

        if (!IsPostBack)
        {
            //check if chkbtaccess cookies exists
            if (null != Request.Cookies[CHECKACCESS])
            {

                HttpCookie cookieCheckAccess = Request.Cookies[CHECKACCESS];
                string strCKBTC = DecryptUsernamePass(cookieCheckAccess.Value.ToString());

                if (String.Compare(strCKBTC, string.Empty) != 0)
                {
                    string[] aryCKBTC = strCKBTC.Split(Convert.ToChar(","));
                    TextBoxUsername.Text = aryCKBTC[0];
                    TextBoxPassword.Text = aryCKBTC[1];
                    CheckBoxRememberMe.Checked = true;
                }
}

private string DecryptUsernamePassword(string strText)
    {
        string strDecryptedUsernamePassword = string.Empty;
        strDecryptedUsernamePassword = CommonUtil.EncryptDecryptHelper.Decrypt(HttpUtility.UrlDecode(strText, Encoding.Default));
        //strDecryptedUsernamePassword = CommonUtil.EncryptDecryptHelper.Decrypt(HttpUtility.UrlDecode(strText, Encoding.Unicode));

        return strDecryptedUsernamePassword;
    }


private string EncryptUsernamePassword(string strText)
    {
        string strEncryptedUsernamePassword = string.Empty;             
        strEncryptedUsernamePassword = HttpUtility.UrlEncode(CommonUtil.EncryptDecryptHelper.Encrypt(strText), Encoding.Default);
        //strEncryptedUsernamePassword = HttpUtility.UrlEncode(CommonUtil.EncryptDecryptHelper.Encrypt(strText), Encoding.Unicode);

        return strEncryptedUsernamePassword;
    }
A: 

As a starting point, you should add some logging and exception handling in this code so that you can narrow down what the error could be. It would also make your code more robust and tolerant to invalid cookie values.

An easy way to do this would be to implement the error handler in Global.asax:

protected void Application_Error(Object sender, EventArgs e)
{
    Exception exception = Server.GetLastError();
}

This should give you the exception that occurred, which you can then examine (eg. in the debugger, log it to a file, etc...) to see what is causing the error.

For a temporary measure, you could turn off custom errors in web.config:

<customErrors mode="Off"/>

This will enable you to see the exception in your web browser when it occurs. I wouldn't recommend that you use that setting on a live site though.

adrianbanks