reading txt storing in different - asp.net

ASp.NET application.
In button click i am accessing one text file and reading content and storing in other destination.
while both users clicking this button at a time deadlock(thread is being used by other process) will occurs so how to handle this i want to read each user one by one can any one suggest method to handle.
i am looking to handle with waithandle events so can any one give a code sample for above scenario.

You could use a ReaderWriterLockSlim to synchronize access to a shared resource such as a file.

Related

Decoding device information from user agent

Recently, I've add the user agent string when the guests submit the form to the database. There is a report that is generated weekly containing various statistics. I want to add the device and maybe the browser information to the report.
I was pondering that I would create a new database table that would hold all the know user agent strings and have two extra fields, one for the device info, and maybe the browser in the other one. However, I cannot find a site that you can download the strings. Would any one know of a place?
If that can not be done, I was thinking of a .net alternative. How would I go into doing that in .net?
2 ways to do it:
If you are using ASPNET MVC, you could use the default this.Request.Browser within the controller method call (contains quite a lot of info, example here),
You can also use 51Degrees, which has a light and a complete device db to match devices capabilities

Using Ajax=>WebService to save multiple input field values

I am working on ASP.Net webforms i have a user control with multiple input fields around 50-60 fields. The data from these fields is being saved and loaded on a save button click right now which takes alot of time.
I wanted to know if I save the data from these input fields using ajax calling a webservice on the focusout or blur event of the input field! is that a better alternative? And will it cause problems if multiple users are calling this web service so many times!! Any other solutions to my problem will be appreciated :)
No, this is not a good method, as people might end up sending a lot of blank data and this is just a waste of bandwidth. Remember, it will take almost equally long for sending data from all text fields, when compared with sending from one text field. Validation of the data could also be a problem and there will end up being a lot of code redundancies, regarding the extra validation and ajax calls being made. On the other hand, if you use an intermediate server, it can be a lot more responsive, assuming the ping between the intermediate and the user is low and the ping between the intermediate and the back-end server is also low and controlled by you.
Other than that, I don't know of any better method than sending all the data on a form submit.

I have multiple users, can i lock the web page so that only one user at a time can update a record?

Can anyone help or provide me with some suggestions for the below query.
I have a web form (Minutes of Meeting) and 8 users that need to access this web page and update their area. A user may have more than one area to update and essentially i would like to some how lock down the web page if possible when a user is using it so that no other user can update this web page till joe bloggs has finished with it.
I have a Active Directory security group set up to restrict the site to that group of users only, but i need to think of a solution to the above?
Is there a way i can do this via a web control or via SQL?
There must be better ways to do it. However, Is it possible for you to introduce a sql table column similar to "UpdateInProgress" (bit). Any update process sees that column, If 0 then It updates to 1 and after It saves the changes and updates back to 0 so that the form is available for other to update. If update process sees 1, It can't update the web form because update is in progress.
I also suggest to introduce another column named "UpdateInProgressBy" to check who has opened it for editing.
First of all we must note that there is a big time from the moment the user reads the data, get it in a page, change them and then try to write them back. So we are not talking for the lock command on SQL, nether any other lock that happens in milliseconds and help to synchronize threads, but here we must synchronize people and what they write.
There is also a problem if the user leave the page for any reason and this can make the data lock for ever.
This problem can solve with two approaches.
the easy one, when a user try to save data you must check if the same data have been change in the middle, and warn him, or show a merge dialog, or merge programmaticall, or something similar - I do not know what you won.
the difficult way is to constantly monitor the page that read and change the data, and keep this monitor results on a common table in the data base, and there if a user have been and stay on page, the rest users get a warning and read only data, until the user go.
This monitor must be made with javasript and must know even if a user abandon the page.
SET TRANSACTION ISOLATION LEVEL as SERIALIZABLE
for more information check this link:
http://msdn.microsoft.com/en-us/library/ms173763.aspx

Uploading multiple/large files

I have this page where a user can upload documents (multiple documents, size limit 10MB each). It is a two step process. Step 1 has the input form. Step 2 is the preview page with a submit button.
How should I handle the scenario where the user closes the browser while on the preview page, without submitting the form? Should I save the files in a temp location after step 1? Is this a decent solution?
And what are the best practices in general for uploading (reasonably) large files?
Thanks.
Take a look at this:
http://www.codeproject.com/Articles/68374/Upload-Multiple-Files-in-ASP-NET-using-jQuery
One way or another, you'll probably end up looking at a jQuery/AJAX control to do this.
You can use a temporary folder to save the files and copy the files to their final location only on submission of the form.
In any case, it would be better to implement a garbage collector. The garbage collector can empty the temporary folder every night. But when using a garbage collector, if you have a way to identify files that were not submitted (for example, if a row is added to a database upon submission), you can put the files in their final location from the beginning, and let the garbage collector remove them every night.
Upload of large files can be done using a JQuery UI plugin such as Uploadify: http://www.uploadify.com/.
You should pay attention that it uses flash, which on the one hand is very good for uploading large files, but on the other hand it will prevent your application from supporting Apple machines such as iPad.
If the user leaves, then let them start over. More than likely they left for a good reason. If there was a crash, leave the responsibility on their end. If you choose to store their data without them submitting this could allow malicious users to exploit your storage.
You can also look into a process called chunking.
For a more in depth discussion on file uploads in mvc3, see this SO post: MVC 3 file upload and model binding

Need an application design advice

I'm developing a web application which processes invoices(the functionality is not limited to invoices, but it doesn't matter). One of the parts of the workflow is to print invoice after it was published. This means that the website user is able to select 10-20(and more) invoices and print it at once. Also there may be several invoice templates which may be customizable(this is one of the key requirements).
I should also mention that we decide to generate PDFs from the html code and then print it. So as the PDF creation process may take some time to complete we decided to use a windows service for invoices printing.
So, summarizing we have the following requirements:
There should be customizable invoice
templates;
The website user should be
able to specify which template he
want to use with the invoice item
specified;
There should be a possibility to
print one or several selected
invoices in one click.
Our first idea was to use user controls as invoice templates. The user control will be responsible for invoice layout. This also means there will be a base class for these user controls through which we will be able to define a data source for the controls.
In this case we may even allow users to modify ascx file (or something similar) to edit basic captions if necessary.
The problem begins in the windows service where we are unable to generate output for user controls. So the other solution is to use http handler or web service to generate user controls output and transfer this to the windows service. But this complicates the solution (e.g. we need to use authentication for this and similar problems).
Maybe there is a much more simpler way to do it?
Thanks in advance.
In response to your comment, I suggest you have the website generate the HTML and save it into a 'GeneratedInvoice' field in your DB, which the service then processes (i.e. converts to PDF however your pdf conversion software does it). It's appropriate because you have a 'saved' copy of the generated invoice; i.e. if your invoice processing routine changes (different styles, etc) your old invoices aren't affected, and yet you can regenerate a given bunch in a possibly 'new' format if required.

Resources