ASP.Net File Upload with CRC check - asp.net

Is there a file upload control for ASP.Net which performs a client-side checksum calculation (CRC, MD5, etc) on the file contents and transmits the checksum to allow for server-side checksum validation?
I have looked through answers on several file upload questions, but did not find this feature mentioned anywhere.

From javascript you won't be able to detect the size of a file in the client computer. Javascript runs inside a sandbox and cannot access local system files, which will be a ecurity violation.
You can use silverlight and can get the file size and calculate the sum. You can check this
Silverlight File Uplaod

You'll need some client code to open your file, compute that check sum and to post it to your webserver with your file content; you can't do that with plain javascript, as you're not supposed to have access to your user filesystem.
But, just like #Dan Herbert commented out into your question, to use a client application like Flash, Java applet or Silverlight to execute that. I just wanted to make a more complete answer and to explain why you can't do that.

Related

Executing a Classic ASP Encrypted file in browser

I have encrypted my ASP File. But when i run it in browser it fails. How to execute that asp file so that my application could run ?
how to decrypt it, it is encrypted using a tool , how do I decrypt it while execution ? I don't want that anybody whom I give that file , sees the code of the file , but could only execute it and use it.
Ah, I think I understand:
ASPEncrypt is a component you can use to encrypt files using ASP or ASP.NET. It is NOT a tool to encrypt your ASP(.NET) source code files with.
You're looking for something like Microsoft script encoder (I don't know if it's still available), you want your sourcecode to be unreadable right?
There are tools that claim to do this, but there isn't one I know of that can't be reversed. So it's only a small obstacle if someone really wants to get their hands on your code.
Here are some more tools that claim to do this.
I hope one of them suits your needs.

How to push data from excel to SQL Server?

I have written a simple ASP.NET MVC 2 application that stores data and can dynamically create excel files using Microsoft's openXML for excel files.
What is the best way to push changes the user makes in excel to my database? I know it can be done via file upload, but this is rather obtrusive to the end user to navigate to my site, select upload, and then select their file.
Is there a way to do 1 click publishing from the excel file using VBA? VBA can interact with the database directly, but this seems dangerous from a data security standpoint, and duplication of logic.
Do web services work with the MVC architecture? How do I get a vba macro enabled document to send itself to the server?
For anyone out there looking for a fix, I ended up using vba's InternetExplorer.Application object and interacting with an upload form on my site.
For more info on the upload form check out:
http://haacked.com/archive/2010/07/16/uploading-files-with-aspnetmvc.aspx
For more info on VBA and the InternetExplorer.Application object check out:
www.motobit.com/tips/detpg_uploadvbaie/
You might take a look at Sql server integration services for bulk upload of data into sql server. The integration services once created can be run using a normal c# desktop program or using a windows service.
But you might
need to make sure this happens in the background and will have to be
an asynchronous task.
also need to make sure it is properly secured
by not giving direct execute access to any other users
I'm assuming that this is for a specific user. I've done something very similar to what you are describing before.
Tell the user to save the excel file in their DropBox and share the file with you.
Have the server listen for changes to this file and run a server side routine to import the data.
Disclaimer: This is not a secure solution, but it's easy and will get the job done.

how to prevent uploading of exe file in asp.net mvc

I am looking for a good solution by which we can prevent an exe file to be uploaded on server.
It will be best if we can discard the upload by just reading the file headers as soon as we receive them rather than waiting for entire file to upload.
I have already implemented the extension check, looking for a better solution.
There is a how and a when/where part. The how is fairly simple, as binary files do contain a header and the header is fairly easy to strip out and check. For windows files, you can check the article Executable-File Header Format. Similar formats are used for other binary types, so you can determine types you allow and those you do not.
NOTE: Linked article is for full querying of the file. There are cheap, down and dirty, shortcuts where you only examine a few bytes.
The when/where depends on how you are getting the files. If you are using a highly abstracted methodology (upload library), which is fairly normal, you may have to stream the entire file before you can start querying the bits. Whether it is streamed into memory or you have to save and delete depends on your coding and possibly even the library. If you control the streaming up, you have the ability to stream in the first bytes (header portion) and abort the process in mid stream.
The first point of access to uploaded data would be in a HttpModule.
Technically you can check before all the bytes are sent if you have an .exe on your hands and cancel the upload. It can get quite complicated depending on how far you want to take this.
I suggest you look at the HttpModule of Brettle's NeatUpload. Maybe it gives you a lead on how to deal with this on the level you want.
I think you can do that by a javascript by checking if the file end with .exe before submitting the data and also do the check server side.

concurrent reading and writing image files (asp.net, but applies to most web languages)

I have a .jpg file which represents the current image from a webcam. User's will be downloading this file at an interval of once a second. Because there could be dozens of users reading it, this could be dozens of times a second (which is normal for any web server).
Problem is, this image is updated by a 3rd party application also once a second which "spiders" my local networks webcam portal image. This is so we can build our webcams into our current administration panel.
The problem I am already finding is ASP.net sometimes gets an error it can not access the file because it is open for write permissions by the bot. Likewise, the bot can not access it because IIS is feeding it to the user.
The bot uses io.streamwriter to save the data to the file, and my script uses Response.WriteFile to send the file to the script. (I need to use an actual ASP.net page with a JPG content-type that feeds the file to make sure only users with a active session can view the JPG).
My question is what is the best practices for this? I know why it's happening but what is the best resolution for this? Would storing as a BLOB in a database maybe be smarter since databases are created for concurrent read/writing already? Is there an easier way of doing this with a file I have not thought of yet?
Thanks in advance,
Anthony Greco
Using a BLOB will work if the readers use SNAPSHOT isolation model (SQL Server 2005 and up). See Download and Upload images from SQL Server via ASP.Net MVC for how to stream an image from a BLOB, and see Understanding Row Versioning-Based Isolation Levels for a lecture on SNAPSHOT.
But using a BLOB may be overkill, you could get away with something much simpler. For instance, if you only have one ASP.Net process, then you could have a global volatile variable for the current file name. The writer writes the JPG into a new file, and then updates the global 'current' file name with an Interlocked.CompareExchange operation (it has to be Compare because a newer writer might actually finish faster, outrun a previous writer, and you want to preserve the latest update). There are still some issues left to solve (find out the file name at startup, clean up old files etc) but they are all fairly ease to solve.
If you have a farm of servers, or multiple ASP.Net processes serving the site, then things could get complicated. I would still do a rotating file name and do a try-and-error approach (try to respond with newest file, fall back to previous older one if conflict is detected).
You could get the bot to write the data to a different filename and then do a delete and rename to the filename being served by ASP.Net. This should reduce the file lock time down to the time for a delete and rename to occur. To clarify:
ASP.Net serving image from "webcam.jpg"
bot writes image data to "temp.jpg"
when last image byte written, bot deletes "webcam.jpg" and renames "temp.jpg" to "webcam.jpg"
ASP.Net should check "webcam.jpg" exists, if not wait 10ms (or suitable small increment) and check again.

Flex Write File

I checked in the API, that writing a file is only in Flex Air.
Despite of that, is there still a way in Flex to write a file on the server or on the client machine ?
More concretely, it's because I have a String and I will decode it by mx.utils.Base64Decoder
to a doc. And I need to open it by Word directly on the client side, or write it on the server and return the link to the client for downloading.
Thanks
I'm doing something similar - I have built a custom grid in Flex that contains an additional button on it that allows the user to open the data up in Excel. I've done this by writing a function in PHP on the server which my Flex speaks to. This creates the CSV file on the server and the function passes the link back to the client, which in turn offers the user the chance to open the data up in Excel.
I'm using the Zend technologies to accomplish this - I recommend you take a look; they're extremely good. I used to use Flex Data Services and Java do do this but just recently switched to PHP because development time is cut down drastically as a result.
Hope this helps.
Jamie.
AIR applications run on the users' desktops. They allow you to write to the users' desktops. Nothing stops Flex/AIR applications from communicating to the server, write some files there (using a suitable backend technology) and return a link back to the user.

Resources