Last post Sep 09, 2014 04:33 PM by AidyF
Sep 09, 2014 02:56 PM|matt.gulick|LINK
I encountered a problem in the past with the values generated by a class method being shared with several users .......... the last user whose actions caused the method to be called was the one that appeared to set the current values that were shared among
all users calling those properties (or whatever they were). I eventually caught this and corrected it, but unfortunately I did not document the problem in any detail ................................. so now I am afraid that I am making the same mistake. All
that I recall is that the word "static" and Class file method was involved.
It could have been that I was not instantiating anything ............. but alas, my memory is not what it use to be.
Can anyone tell me if they see anything inherently wrong with how I am implementing this method?
After a user selects a file on web page, this class file method (IsFileExtensionAllowed) is called by the web page's code behind (on Click)
public static List<ExitStatus> IsFileExtensionAllowed(AsyncFileUpload afu, FileType fileType)
List<ExitStatus> list = new List<ExitStatus>();
ExitStatus exitStatus = new ExitStatus();
exitStatus.Success = true;
string sql = "SELECT TEXTVALUE FROM LISTS WHERE FK_COLUMNNAME = 'FILE_TYPE' ";
sql += "AND TAGS = '" + fileType + "'";
List<string> allowedExtenstions = DatabaseServices.ExecuteQuery_DataTable(sql).Rows.OfType<DataRow>().Select(dr => dr.Field<string>("TEXTVALUE")).ToList();
string allowedFileTypes = string.Join(", ", allowedExtenstions);
if (afu.FileName.Contains(".") && !allowedExtenstions.Any(afu.FileName.Split('.').ToLower().Contains))
exitStatus.Success = false;
exitStatus.Message = afu.FileName.Split('.') + " is not a valid " + WebSite.Helper.GetEnumDescription(fileType) + @" extension. \n\nValid extensions are: " + allowedFileTypes;
My concern is that multiple users calling the method could experience issue.
Thanks for your time and council.
Sep 09, 2014 03:23 PM|MetalAsp.Net|LINK
I don't see anything wrong with your code. The "other" issue you faced was probably declaring a static variable; in that case, the variable would be shared among all users, which in most cases is not what you'd want. But since you're not using any static
variables in the code you posted, I don't see any problem.
Sep 09, 2014 03:48 PM|matt.gulick|LINK
So as long as I instantiate, the values returned from the method will always be unique to the browser session that called it, no matter how many different browsers are calling the same method at the same time?
Sep 09, 2014 04:33 PM|AidyF|LINK
Local non-static variables inside a static function still get their own local copies of the variables so each request will only see its own data. As mentioned, you run into problems when your variables are static rather than your methods.