asp.net multiple user calculation error - asp.net

Apologies if this has been asked/solved before. I've done a fair bit of searching but can't seem to find a direct answer to my problem.
I'm still very new to asp/vb coding.
I've created a complex calculator in asp.net using vb.net.
The user fills out a few text boxes with information then clicks the calculate button. The program then accesses an sql 2014 server to collect more information based on information the user has entered, then uses the information to run a few very complex calculations (I don't completely understand the calculations behind it).
It all works fine and is able to give the correct answer, the problem I've found is if there is more than one user accessing the site and they happen to click the calculate button within the same time, whoever clicked the calculate button first gets an error whilst the person who clicked second gets an answer.
I'm not sure if this is to do with how it accesses the sql database for information or if the information is somehow being overridden.
I was hoping this would be a common problem, but can't seem to find anything on it, at least I may not be asking the right question when searching.
Unfortunately for security reasons I'm not able to post any code for it (I'll see if I can get permission) but am hoping that someone has come across something similar and knows a work around. Maybe to have the site wait until the first round of calculations is complete before initiating the second round?
Thanks for your help in advance!

Please make sure that you should not use any shared variable in calculation because shared variables are common for all users. Also check for application variables.
I can understand, but if those public variable's value changed at one place, then after everywhere that variable's value will be new even if you are in middle of some processing.

Related

Editing the cooldowns of spells and spell like effects

I am trying to reduce the cooldown on the hearthstone and inscription research spell-like effects. I have identified the hearthstone item template and imported the hearthstone spell into spell_dbc. I have set the spell category cooldown to 1 second, but I am experiencing a strange issue. On use, the hearthstone is set to a 30-minute cooldown and not useable during this cooldown, but on logging out and logging back in, the correct cooldown is displayed and the item is useable once the cooldown has expired. I suspect that the client is tracking the cooldown of the hearthstone independently of the server. But I have no clue where to begin looking to fix this. Has anybody successfully made a change to spell cooldowns, and would you be willing to point me in the right direction?
Thank you!
Not a solution to your problem, but I'm pretty sure that what you are experiencing is actually an intended behavior to discourage hacking.
I think what is really going on is your login credentials are being used to create a secret that is then passed into the rest of their program, which is then used as a reference point for debugging.
Because they know the intended behavior of their own game, they can check to see if the results of arguments sent from your machine are within expected parameters.
And because your modifications fall outside of those parameters, what the developers decided to do was to change the cooldown to something sufficiently annoying to detect who keeps on manually logging out and logging back in again.
I studied programming in college, and I'm telling you that if you know enough to change the cooldowns locally, you should try doing something more productive. Either find another game to play at the same time, or just do something completely different from gaming altogether.
Hope somebody double checks what I have said here for accuracy, because I am curious to know if I am correct about my assessment.
The solution is to delete the client cache.

Checking for form correctness in visual basic

I'm developing a small web app using ASP.net/VB.net4 that contains an important form on one of the pages. I need to make sure that the form is filled out correctly, and have decided to go with custom logic to do this, writing each check by hand and checking every element on the page.
My question is actually more fundamental here -- I have the checks written to make sure that the form passes correctness, but I don't actually know in what programmatical structure to put these checks.
For now, I put the checks in an infinite loop in my Visual Basic code behind.
While (True)
If (...) Then
MsgBox("One or more of your phone numbers is improperly formatted. You will be given 20 seconds to correct this mistake. If the mistake is not corrected in 20 seconds, you will be eliminated. Good luck.")
ElseIf (...) Then
...............
Else
Exit While
End If
End While
Upon hitting the submit button, the loop activates and the checks are completed -- however, there is an issue with this method. When the form is not correct, then my alert message continues to pop up infinitely and does not allow the user to exit out. If anyone knows how to avoid this, that would be an appreciated place to start. Furthermore, the default alert box for VB.net is just ugly and unprofessional, I would prefer something in-browser if possible, rather than just an ugly Windows alert message box.
I've seen a lot of sites now going with a dynamic check; that is, as you fill out the form, if at any point your entry is not formatted properly or is incorrect, you get an automatic alert that tells you this and perhaps the text box color changes to red. I would like to do it this way, if possible, since this seems easier for the user. However, I do not know how to do this and have had trouble finding information online about how to implement this. I believe this is an example of AJAX/jQuery usage but it has been a while since I've used them.
This is a painfully common thing to have to do, forms logic that is. I know there are a million and a half ways to do this, but does anyone have any advice or recommendation on how to implement this? Should I be trying to use vb.net (code behind), javascript, or some other way?

SQL - Whole Records Being Cleared Out Through ASP.NET Web Forms Application

I'm part of a team building a large ASP.NET Web Forms application, and have recently gotten complaints that some records are being "cleared out" after being created -- in this case they create an "inventory" item, save it, and then perhaps after editing some of the data and re-saving, all of the fields are suddenly blank.
I realize that this could be some faulty logic on the save, in which case it will be difficult for you to offer insight, but we've never come across this particular issue before, and haven't really touched the logic. I'm wondering if anyone has some insight into what could possibly be going on, if it's possible that something sporadically happens on the client which makes the values of the input fields blank or unreadable...? I don't know, I'm a bit in the dark and frustrated because I can't reproduce the behavior, and we're losing a bunch of data.
Thanks in advance for any bit of direction or advice.
Related issues in WebForms are often caused by logic related to Page.IsPostBack and values being reset.
Without code it's hard to say; I'd suggest adding some temporary code to log the posted data (and function calls down the line to the database writes). Without logging you're blind.

Paypal Button creation/encryption

I've search for this online but couldn't find anything conclusive, yet.
I wish to make a large (yet unknown) number of paypal buttons, different prices, currencies, etc.
I have been following the encryption methodology and I came to a stop/point of additional research when I discovered that each encrypted button must be created on the command line and copied to my website.
This doesn't seem feasible if I require a large number of buttons, and due to this (apparent) absurdity I feel that I must be missing something obvious? Some sites have 100s/1000s of different prices/buttons which must be dynamically created.
Or is the correct procedure to leave the buttons unencrypted, thus dynamically created, and then use the IPN Listener to validate payments?
I'd be happy if someone could just point me towards a few tutorials/webpages.
Thank-you kindly for the help
Joseph
This will give you a start:
https://www.paypal.com/us/cgi-bin/webscr?cmd=_pdn_xclick_techview_outside
I use custom created buttons all the time.

Best Practices for Passing Data Between Pages

The Problem
In the stack that we re-use between projects, we are putting a little bit too much data in the session for passing data between pages. This was good in theory because it prevents tampering, replay attacks, and so on, but it creates as many problems as it solves.
Session loss itself is an issue, although it's mostly handled by implementing Session State Server (or by using SQL Server). More importantly, it's tricky to make the back button work correctly, and it's also extra work to create a situation where a user can, say, open the same screen in three tabs to work on different records.
And that's just the tip of the iceberg.
There are workarounds for most of these issues, but as I grind away, all this friction gives me the feeling that passing data between pages using session is the wrong direction.
What I really want to do here is come up with a best practice that my shop can use all the time for passing data between pages, and then, for new apps, replace key parts of our stack that currently rely on Session.
It would also be nice if the final solution did not result in mountains of boilerplate plumbing code.
Proposed Solutions
Session
As mentioned above, leaning heavily on Session seems like a good idea, but it breaks the back button and causes some other problems.
There may be ways to get around all the problems, but it seems like a lot of extra work.
One thing that's very nice about using session is the fact that tampering is just not an issue. Compared to passing everything via the unencrypted QueryString, you end up writing much less guard code.
Cross-Page Posting
In truth I've barely considered this option. I have a problem with how tightly coupled it makes the pages -- if I start doing PreviousPage.FindControl("SomeTextBox"), that seems like a maintenance problem if I ever want to get to this page from another page that maybe does not have a control called SomeTextBox.
It seems limited in other ways as well. Maybe I want to get to the page via a link, for instance.
QueryString
I'm currently leaning towards this strategy, like in the olden days. But I probably want my QueryString to be encrypted to make it harder to tamper with, and I would like to handle the problem of replay attacks as well.
On 4 guys from Rolla, there's an article about this.
However, it should be possible to create an HttpModule that takes care of all this and removes all the encryption sausage-making from the page. Sure enough, Mads Kristensen has an article where he released one. However, the comments make it sound like it has problems with extremely common scenarios.
Other Options
Of course this is not an exaustive look at the options, but rather the main options I'm considering. This link contains a more complete list. The ones I didn't mention such as Cookies and the Cache not appropriate for the purpose of passing data between pages.
In Closing...
So, how are you handling the problem of passing data between pages? What hidden gotchas did you have to work around, and are there any pre-existing tools around this that solve them all flawlessly? Do you feel like you've got a solution that you're completely happy with?
Thanks in advance!
Update: Just in case I'm not being clear enough, by 'passing data between pages' I'm talking about, for instance, passing a CustomerID key from a CustomerSearch.aspx page to Customers.aspx, where the Customer will be opened and editing can occur.
First, the problems with which you are dealing relate to handling state in a state-less environment. The struggles you are having are not new and it is probably one of the things that makes web development harder than windows development or the development of an executable.
With respect to web development, you have five choices, as far as I'm aware, for handling user-specific state which can all be used in combination with each other. You will find that no one solution works for everything. Instead, you need to determine when to use each solution:
Query string - Query strings are good for passing pointers to data (e.g. primary key values) or state values. Query strings by themselves should not be assumed to be secure even if encrypted because of replay. In addition, some browsers have a limit on the length of the url. However, query strings have some advantages such as that they can be bookmarked and emailed to people and are inherently stateless if not used with anything else.
Cookies - Cookies are good for storing very tiny amounts of information for a particular user. The problem is that cookies also have a size limitation after which it will simply truncate the data so you have to be careful with putting custom data in a cookie. In addition, users can kill cookies or stop their use (although that would prevent use of standard Session as well). Similar to query strings, cookies are better, IMO, for pointers to data than for the data itself unless the data is tiny.
Form data - Form data can take quite a bit of information however at the cost of post times and in some cases reload times. ASP.NET's ViewState uses hidden form variables to maintain information. Passing data between pages using something like ViewState has the advantage of working nicer with the back button but can easily create ginormous pages which slow down the experience for the user. In general, ASP.NET model does not work on cross page posting (although it is possible) but instead works on posts back to the same page and from there navigating to the next page.
Session - Session is good for information that relates to a process with which the user is progressing or for general settings. You can store quite a bit of information into session at the cost of server memory or load times from the databases. Conceptually, Session works by loading the entire wad of data for the user all at once either from memory or from a state server. That means that if you have a very large set of data you probably do not want to put it into session. Session can create some back button problems which must be weighed against what the user is actually trying to accomplish. In general you will find that the back button can be the bane of the web developer.
Database - The last solution (which again can be used in combination with others) is that you store the information in the database in its appropriate schema with a column that indicates the state of the item. For example, if you were handling the creation of an order, you could store the order in the Order table with a "state" column that determines whether it was a real order or not. You would store the order identifier in the query string or session. The web site would continue to write data into the table to update the various parts and child items until eventually the user is able to declare that they are done and the order's state is marked as being a real order. This can complicate reports and queries in that they all need to differentiate "real" items from ones that are in process.
One of the items mentioned in your later link was Application Cache. I wouldn't consider this to be user-specific since it is application wide. (It can obviously be shoe-horned into being user-specific but I wouldn't recommend that either). I've never played with storing data in the HttpContext outside of passing it to a handler or module but I'd be skeptical that it was any different than the above mentioned solutions.
In general, there is no one solution to rule them all. The best approach is to assume on each page that the user could have navigated to that page from anywhere (as opposed to assuming they got there by using a link on another page). If you do that, back button issues become easier to handle (although still a pain). In my development, I use the first four extensively and on occasion resort to the last solution when the need calls for it.
Alright, so I want to preface my answer with this; Thomas clearly has the most accurate and comprehensive answer so far for people starting fresh. This answer isn't in the same vein at all. My answer is coming from a "business developer's" standpoint. As we all know too well; sometimes it's just not feasible to spend money re-writing something that already exists and "works"... at least not all in one shot. Sometimes it's best to implement a solution which will let you migrate to a better alternative over time.
The only thing I'd say Thomas is missing is; client-side javascript state. Where I work we've found customers are coming to expect "Web 2.0"-type applications more and more. We've also found these sorts of applications typically result in much higher user satisfaction. With a little practice, and the help of some really great javascript libraries like jQuery (we've even started using GWT and found it to be AWESOME) communicating with JSON-based REST services implemented in WCF can be trivial. This approach also provides a very nice way to start moving towards a SOA-based architecture, and clean separation of UI and business logic.
But I digress.
It sounds to me as though you already have an application, and you've already stretched the limits of ASP.NET's built-in session state management. So... here's my suggestion (assuming you've already tried ASP.NET's out-of-process session management, which scales signifigantly better than the in-process/on-box session management, and it sounds like you have because you mentioned it); NCache.
NCache provides you with a "drop-in" replacement for ASP.NET's session management options. It's super easy to implement, and could "band-aid" your application more than well enough to get you through - without any significant investment in refactoring your existing codebase immediately.
You can use the extra time and money to start reducing your technical debt by focusing new development on things with immediate business-value - using a new approach (such as any of the alternatives offered in the other answers, or mine).
Just my thoughts.
Several months later, I thought I would update this question with the technique I ended up going with, since it has worked out so well.
After playing with more involved session state handling (which resulted in a lot of broken back buttons and so on) I ended up rolling my own code to handle encrypted QueryStrings. It's been a huge win -- all of my problem scenarios (back button, multiple tabs open at the same time, lost session state, etc) are solved and the complexity is minimal since the usage is very familiar.
This is still not a magic bullet for everything but I think it's good for about 90% of the scenarios you run into.
Details
I built a class called CorePage that inherits from Page. It has methods called SecureRequest and SecureRedirect.
So you might call:
SecureRedirect(String.Format("Orders.aspx?ClientID={0}&OrderID={1}, ClientID, OrderID)
CorePage parses out the QueryString and encrypts it into a QueryString variable called CoreSecure. So the actual request looks like this:
Orders.aspx?CoreSecure=1IHXaPzUCYrdmWPkkkuThEes%2fIs4l6grKaznFGAeDDI%3d
If available, the currently logged in UserID is added to the encryption key, so replay attacks are not as much of a problem.
From there, you can call:
X = SecureRequest("ClientID")
Conclusion
Everything works seamlessly, using familiar syntax.
Over the last several months I've also adapted this code to work with edge cases, such as hyperlinks that trigger a download - sometimes you need to generate a hyperlink on the client that has a secure QueryString. That works really well.
Let me know if you would like to see this code and I will put it up somewhere.
One last thought: it's weird to accept my own answer over some of the very thoughtful posts other people put on here, but this really does seem to be the ultimate answer to my problem. Thanks to everyone who helped get me there.
After going through all the above scenarios and answers and this link Data pasing methods My final advice would be :
COOKIES for:
ENCRYPT[userId's]
ENCRYPT[productId]
ENCRYPT[xyzIds..]
ENCRYPT[etc..]
DATABASE for:
datasets BY COOKIE ID
datatables BY COOKIE ID
all other large chunks BY COOKIE ID
My advise also depends on the below statistics and this link details Data pasing methods :
I would never do this. I have never had any issues storing all session data in the database, loading it based on the users cookie. It's a session as far as anything is concerned, but I maintain control over it. Don't give up control of your session data to your web server...
With a little work, you can support sub sessions, and allow multi-tasking in different tabs/windows.
As a starting point, I find using the critical data elements, such as a Customer ID, best put into the query string for processing. You can easily track/filter bad data coming off of these elements, and it also allows for some integration with e-mail or other related sites/applications.
In a previous application, the only way to view an employee or a request record involving them was to log into the application, do a search for the employee or do a search for recent records to find the record in question. This became problematic and a big time sink when somebody from a related department needed to do a simple view on records for auditing purposes.
In the rewrite, I made both the employee Id, and request Ids available through a basic URL of "ViewEmployee.aspx?Id=XXX" and "ViewRequest.aspx?Id=XXX". The application was setup to A) filter out bad Ids and B) authenticate and authorize the user before allowing them to these pages. What this allowed the primarily application users to do was to send simple e-mails to the auditors with a URL in the e-mail. When they were in a big hurry, they were in their bulk processing time, they were able to simply click down a list of URLs and do the appropriate processing.
Other session related data, such as modification dates and maintaining the "state" of the user's interaction with the application gets a little more complex, but hopefully this provides a starting poing for you.

Resources