I have created a web forms application using ASP.NET with C# (.NET 4.7.2) as the code behind. I am using ADO.NET Entity as the connection to a SQL Server 2019 database.
I have created a page with 2 text boxes. Reference number and code. When a user enters Reference number and code into the boxes and click submit the data is stored in the database the page redirects to a detailed page using URL parameters of details.aspx?ref=xxxxxx&c=xxxxxx.
The details.aspx page then loads. Using the code behind page load section, I retrieve the URL parameters from Request.QueryString. Using the results of the query I filter a record set and display some text & image data.
The issue I'm seeing is if 2 users press the submit button at the same time using different data they get a mixture of each others data returned on the next page. If they press it at different times it works fine (we confirmed this using 2 laptops being pressed at the same time by the same person).
Does anyone have any pointers as we have done a lot of searching and at this time and cannot find a solution.
So far we have tried:
IIS Caching - prevent all caching on user-mode and Kernel mode
Adding the following to the page load section of each page
Response.CacheControl = "private";
Response.ExpiresAbsolute = DateTime.Now.AddDays(-1d);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Cookies are not being used
We have full access to the Web Server/Database
Any help would be appreciated
Hi After reading Aristos comment I modified the code and removed static class where I had put global variables. Once I had recoded the page to use local variables all worked as expected.
Thanks for the tip.
I did come across a few post which indicated the same but had not got round to trying that yet.
Many Thanks
Related
I'm trying to use Jmeter to simulate adding values, into a database from an ASP.NET website.
I have used the guide found here: https://www.youtube.com/watch?v=zYAiBwJK1v8
To setup the test, and to record the scenario. All of that seems to be working fine. The recorder, records the login to the site, and everything that comes after, including when I push the submit button to add the value to my database. When i afterwards run the recorded scenario it runs with no errors. But nothing is submittet to the database.
The scenario is this: I login to my site, (i'm using browser session id to differ between users)
Now I search for an item, the search text is parsed along with the url (this i can also confirm in the recording, in Jmeter)
Then i add this item to a tabel row in my databse using a submit button. (this also seems to be working in the recording details in Jmeter)
But nothing is added to the database when i use Jmeter to re-run the scenario. Can any one help me to find out, why or what I am missing?
I'm not sure what more information to give, but if you need more information let me know and thank you in advance
First of all I'd recommend checking that your Log In is successful using View Results Tree listener. At top left corner of the listener there will be a drop-down which defaults to Text. Select HTML (download resources) to see full response from server and verify if you're really logged in.
If not, refer to ASP.NET Login Testing with JMeter guide which highlights the peculiarities of simulating ASP.NET application log in including VIEWSTATE and EVENTVALIDATION dynamic form parameters extraction.
So I'm making a online chat program.
Technologies: -AJAX(methodology) -PHP -C# -ASP.net -JQuery -HTML5 -MYSQL -IIS
Issue (Long):
I've implemented group chat which works fine up to now. My issue is with multi-chat. Mind you I now realize i should have done the entire thing in PHP, but only knew ASP.net and C# when i started and will end up using PHP only, as a last resort. Anyway, when a multi-chat window is made, it injects the pre-made code via jquery into a div, stores it in sessionStorage for when the page refreshes, it loads the code from sessionstorage, and all ID's are incremented by one, for each user to have a max of 6 windows open at any given time. Now i'm trying to get specific query's for each specific users request like "SELECT * WHERE user1 privateChatID = '1' AND user2 privateChatID = '1'; (not the actual query, just pseudo code)", but since i'm using AJAX to get the query, I cant really manipulate the php file since it's loaded because the main file is a .aspx page. Now for group chat I'm using an update panel which works fine, but i can't dynamically make a draggable chat window, inside the update panel, because I'd have to use an ' runat="server" ' attribute, and if i run that in the pre-scripted jquery and wanted to increment the ID (like so: 'IDName "+ i +"'), visual studio/iis gives an error, hence the reason i'm trying to use Ajax. So all the problems I've worked out so far, once i get a working version I'll probably rethink the whole structure all together. My only issue now:
Issue (short):
Would it be easier since i can't manupulate functions or variables in the php file, to just select everything from the DB ('message table') and sort everything client side? or would that not be optimal? OR is there a way to alter query's externally for a php file that is loaded by jquery?
So my solution was to create php files on the server that would have their own queries, and users would have their own directories on the server for those files and i guess any other files that might need to be added to them in the future if any. I'm taking a chance if the load of bandwidth is too much because a number of users will be creating files on the server, when a chat window is create, i don't even know how secure it'll be but it's working for the time being, i'll tweak security issues, after i can get everything working.
How to extract the extra content loaded in a web page, which will not be visible in view page source. The extra content is being loaded using ajax. This data can be seen under NET tab using firebug. How to extract this data using c# code.
Two ways :
1- You can use webbrowser to load the same page and get the active document.
2- You can replicate the ajax call made, and use that to get the extra bits that are appended to the document.
And reading your linkedin example above:
When you select the checkbox a ajax call is made , which brings back results and populates the table.You can see that call using firebug console window and see the post parameter and replicate them to get the same result.
Depends on your application in the first place, if you are using c# application as the client for reading a web page, then the the ajax content may not be visible until you put in a javascript engine.
if you are serving the said pages, you only have to log the request response of the server.
More specific question would be appreciated
That extra content is dynamically generated by ajax (for eg: Gridview is generated as table), it is stored in browser's memory. and can be viewed by client side debugging tools (IE has developer tools option).
Once you do a post back, all the control's values are available for C#.
If you are saying extra content, can you please clarify what exactly you are trying to extract using c#?
I have now been working as a web developer for two weeks and have written my first page connected it to database have everything setup the way I want and now my next big hurdle. I want to get to this page from another page. the second page emulates written forms and the first page will have a grid of the submitted forms. Looking through the net I have found Iframes and there are a couple of other options I am still reading up about, but i wanted to pose the question here as well. What is the generally accepted / good practice method for navigating from page to page in asp.net. Going from database to web has been a trip but its one i am enjoying.
Thank you for any suggestions
Response.Redirect("Default1.aspx"):
we want to redirect the request to some plain HTML pages on our server or to some other web server
we don't care about causing additional roundtrips to the server on each request
we do not need to preserve Query String and Form Variables from the original request
we want our users to be able to see the new redirected URL where he is redirected in his browser (and be able to bookmark it if its necessary)
Server.Transfer("Default1.aspx") :
we want to transfer current page request to another .aspx page on the same server
we want to preserve server resources and avoid the unnecessary roundtrips to the server
we want to preserve Query String and Form Variables (optionally)
we don't need to show the real URL where we redirected the request in the users Web Browser
If you wanted to simply redirect the user you could use Response.Redirect(url), this will redirect the user to the specified relative page. For example, if you were in Page1.aspx and wanted to redirect to Page2.aspx you would simply write
Response.Redirect("~/Page2.aspx");
Please keep in mind, this is a very simple approach to redirecting, and information submitted from Page1 to Page2 won't get persisted, so you'll need to either save these in the database, or in the session.
Hope this helps a bit. :)
Edit
Reading your question further; if you wanted to load a form after selecting it in Page1, you would want to somehow pass it through to Page2. The easiest way would be to append it to the query string, and then check if the query string value exists on Page2 loads.
You can navigate to another page using
Response.Transfer("Default2.aspx");
Else you can use
Server.Transfer("Default.aspx")
but it is bulky since it transfer that data of previous page too..
Response.Redirect does the job of navigating from one page to another. Below is good article which explains the correct use of it, hope this helps.
http://blogs.msdn.com/b/tmarq/archive/2009/06/25/correct-use-of-system-web-httpresponse-redirect.aspx
Sorry if this is duplicate but I've been going crazy for the past two hours over this.
After changing the Master Page in ASP.NET MVC 1.0 application, I keep getting this familiar error when I try a postback without filling in the mandatory form elements which are validated by the server:
"Validation of viewstate MAC failed.
If this application is hosted by a Web
Farm or cluster, ensure that
configuration specifies
the same validationKey and validation
algorithm. AutoGenerate cannot be used
in a cluster."
The new page refers to a lot of jQuery code with lightboxes, superfish etc. Could that be a problem while doing a postback?
If I revert back to the original master, the error disappears and I'm able to validate form fields. Both masters are located in the same path.
I know a lot of other guys have faced this issue but I was unable to find anything which could help me.
Thanks.
Edited and added
After a little debugging, I've realized that a directive in the master page:
<% Html.RenderAction("menu", "nav"); %>
is creating the problem. The directive asks the "menu" action of the controller "nav" to inject a partial view Menu.ascx. If I delete this line from the new master page, everything works OK. My app's left bar navigation relies on this directive to work properly. Is there any way I can get around this? Very mysterious.
Are you using Html.AntiForgeryToken() anywhere on this page? Sometimes when I am testing locally with multiple different sites and / or port changes this will happen to me. If it does I clear my browser cache and it works just fine.
I did experienced the same problem two days ago. :)
A simple restart of the box has worked in my case so I did'nt investigate further.