ASP.NET - Having issues with value in a class - not changing

CipherIS
CipherIS used Ask the Experts™
on
I have a Session["AccessKey"].  I am passing the value to a Class "CustomerAccessKey".  Then I call FileList.getFiles to bind it to the repeater.  In this class I need the "CustomerAccessKey" value.  

When i run the website the first time and use key "1234" it gets the data correctly.  
I log out.  
Log back in and have key = "3456".
I see it being set in "CustomerAccessKey" as "3456" but in FileList.GetFiles the CustomerAccessKey = "1234".  

How do I fix?

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
         //Access Key
         CustomerAccessKey.getCustomerAccessKey = Session["AccessKey"].ToString();
         //Get Files
         rptFiles.DataSource = FileList.getFiles;
         rptFiles.DataBind();
    }
}

Open in new window


public class FileList
{
    static FileList()
    {
        IMDRTransferService _getFiles = new MDRTransferServiceClient();

        getFiles = new List<Files>();
        foreach (var files in 
                _getFiles.CustomerFiles(CustomerAccessKey.getCustomerAccessKey))
        {
            getFiles.Add(new Files() { FileName = files.FileName, 
                                                        DisplayName = files.DisplayName });
         }                   
    }
    public static List<Files> getFiles { get; set; }
 }

public class Files
{
    public string FileName { get; set; }
    public string DisplayName { get; set; }
}

Open in new window


public class CustomerAccessKey
{
    public static string getCustomerAccessKey { get; set; }
}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
This is precisely because you are using static constructor in FileList Type, which will be called only once during entire application and that is at the time of AppDomain Creation.

When you make the call to FileList For very first time(ie. during first login with 1234 id), the constructor gets called and file list is loaded.

Any furthur calls to get files will never call the static constructor.

If you want to load files again, create a method in the FileList Class namely getFiles and return FilList for this new accesskey....

Author

Commented:
remove the keyword static?  can you give me a code sample of how to fix?
Here is the FileList Type:-

public class FileList
{
    public static List<Files> GetFileList(string accessKey)
    {
        IMDRTransferService _getFiles = new MDRTransferServiceClient();

        var files = new List<Files>();
        foreach (var f in 
                _getFiles.CustomerFiles(accessKey)
        {
           files.Add(new Files() { FileName = f.FileName, 
                                                        DisplayName = f.DisplayName });
         } 
         return files;                  
    }
 }

Open in new window

then call this method from page load as:-

if (!Page.IsPostBack)
    {
         //Access Key
         string accessKey = Session["AccessKey"].ToString();
         //Get Files
         rptFiles.DataSource = FileList.GetFileList(accessKey);
         rptFiles.DataBind();
    }

Open in new window

Author

Commented:
Its not working.  Now its worse.  i'm not receiving any data.

Author

Commented:
I don't know what happened but it seems to be working now.  Thx

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial