I am new to .net. I created one website.I want to implement Zlib compression technique for compressing data in each every page, so that i can access open my website quickly.But i don't know where I have to write code for that and how to implement it. Can yo send me the sample application code or zip file.
If your talking about compressing web pages delivered from the server then gzip is used.
IIS6 Example
Related
So, I'm quite new to the ASP.NET MVC framework. What I need to do is make an API endpoint for a webserver which accepts a HTTP post request that has an image file uploaded to it.
I've looked around and I'm really not sure how to handle this. The closest I've come is this resource:
File Upload and Multipart MIME - ASP.NET Web API
Is this pretty much the only way to do it?
No, you can also send it across as a class that has a string property that contains the base64 encoded contents of the file. You then have to decode the base64 in the web api method (which is still a post) and then save or use the file bytes.
From the client's stand point, the most straight-forward way of doing it is multipart mime. But your question was about web api, and it can handle base64 in say, a json object just fine.
If you don't use multipart mime you'll need javascript that converts the upload into base64. That part of it is beyond the scope of your question.
But strictly speaking multipart is not the only way because I had such a javascript file upload library and that's what I used and it worked fine.
The reason why we used that component was because we wanted thumbnail upload preview of the images (preview first), then a submit button to actually submit to web api. javascript held the images in localstorage until the user hit submit (was a multiple image upload thing).
I am an ASP.NET Developer. I want to develop a web app which will convert all the files with particular extensions from one format to another(eg : .txt to .docx or .docx to .txt) on the client machine. I can't see anything in ASP.NET that can do these things on the client machine. I was going through other SOPs and googling which was suggesting to use Silverlight, WPF, ActiveX scripts etc.
Please provide your suggestions. Thanks,
There would be an iOS App and the .NET WebApi which would require to sync large data or records.
We need to have in Memory Compression on both iOS and .NET WebApi which would compress and decompress the data and then further process.
On iOS App side, we have planned to use in Memory GZip compression using something like below-
http://www.clintharris.net/2009/how-to-gzip-data-in-memory-using-objective-c/
http://www.deusty.com/2007/07/gzip-compressiondecompression.html
On .Net WebApi side, we have planned to use the GZip compression to be developed using-
https://msdn.microsoft.com/en-us/library/system.io.compression.gzipstream%28v=vs.110%29.aspx
Now my question is-
Is it possible to use the GZipStream Class in .Net to compress the JSON string? In .Net data would be fetched from the database into models and then the models would be converted to JSON strings and then that string needs to be compressed before sending to device and same inverse process would be followed when receiving data from the iOS App.
Is there any other best approach then the above which we have planned? Any technical advice, relevant links or some sample code snippet would be very helpful.
The Solution:
Thanks to #puneet for leading this post to get a proper solution.
As my server application is a Asp.Net WebAPI and doesn't have any files (html, css, js etc.) to be transferred from the server to browsers like any traditional website. http://forums.asp.net/t/1771770.aspx
Therefore the Automatic IIS Compression would not work in my case, which can be enabled by following the steps given here- http://www.codeproject.com/Articles/186233/Utilize-gzip-compression-in-IIS
In my case both GZip Requests and Responses need to be handled and for this purpose seperate handlers would be required and in that case I am following these below SO posts-
For Compression: Compress HTTP GET Response
For Decompression: How do enable a .Net web-API to accept g-ziped posts
Another mentionable link- http://benfoster.io/blog/aspnet-web-api-compression
Is it possible to use the GZipStream Class in .Net to compress the JSON string? In .Net data would be fetched from the database into models and then the models would be converted to JSON strings and then that string needs to be compressed before sending to device
Yes it is possible by two ways.
Let the IIS handle it itself by enabling Dynamic Compression.
Write your own code to compress the response
Please follow the answer of this thread for both options.
I tried the second way (using the code given in referenced thread answer) and it worked for me very well.
and same inverse process would be followed when receiving data from the iOS App.
Yes, we can decompress the gZipped data.
[this blog post] (http://blog.kaliatech.com/2013/02/posting-compressed-json-content-to-asp-net-web-api-controller/) has the code for the same.
I haven't tried this one, but it seems fine and should work.
anybody please tell me when to use http & ftp when trying to access files from the server in C#
There are a few considerations when making a decision between http and FTP. I would
Say it depends on who will be consuming your files and for what reason.
I would go http when
Hosting Html pages
Hosting Json / XML data structures that are are representation of data from a database. Hosting Images
Generally when the user is a non technical web user that just needs to read your info.
I would use FTP
When the userbase is limited ( you are not allowing access with a web site)
If you need to allow read and write of large files.
FTP is a potential integration approach for passing information between two systems maybe even between 2 companies.
I need access to a couple of XML files on a remote server. Because of the crossdoamin policies, i cannot do it with jQuery alone, but need a small c# .aspx page, which will act as a gateway for my jQuery to fetch the remote xml from a local file. But how would i best go about this page - what is the simplest structure of such a file?
You could use a "Generic Handler" (ASHX file).
I'll use these kind of files often when sending files to the browser, without the need for an UI (i.e. no visible page content).
In my understanding I see ASHX handlers as "pages without an UI" that have low overhead compared to a normal Page.
Why not a web service?
client code (jQuery) -> your server (WCF) -> external xml
You can quickly create a REST web service with this template.