Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

Has Anyone Got HTTP Compression Working with ASP.NET? -


i've spent quite bit of time on seem going nowhere. have large page want speed up. obvious place start seems http compression, can't seem work me.

after considerable searching, i've tried several variations of code below. kind of works, after refreshing browser, results seem fall apart. turning garbage when page used caching. if turn off caching, page seems right lose css formatting (stored in separate file) , error included js file contains invalid characters.

most of resources i've found on web either old or focused on accessing iis directly. page running on shared hosting account , not have direct access iis7, it's running on.

protected void application_beginrequest(object sender, eventargs e) {     // implement http compression     if (request["http_x_microsoftajax"] == null) // avoid compressing ajax calls     {         // retrieve accepted encodings         string encodings = request.headers.get("accept-encoding");         if (encodings != null)         {             // verify support or gzip (deflate takes preference)             encodings = encodings.tolower();             if (encodings.contains("gzip") || encodings == "*")             {                 response.filter = new gzipstream(response.filter,                     compressionmode.compress);                 response.appendheader("content-encoding", "gzip");                 response.cache.varybyheaders["accept-encoding"] = true;             }             else if (encodings.contains("deflate"))             {                 response.filter = new deflatestream(response.filter,                     compressionmode.compress);                 response.appendheader("content-encoding", "deflate");                 response.cache.varybyheaders["accept-encoding"] = true;             }         }     } } 

is having better success this?

i've had results using gzipstream , deflatestream write output directly, although i'm not familiar response.filter property. give whirl:

string response = "your output body"; string accept = request.headers["accept-encoding"]; if(accept == null) accept = ""; if (response.length < 100 || !(accept.contains("deflate") || accept.contains("gzip")))     response.write(response); else {     byte[] compressed;     bool usedeflate = accept.contains("deflate");     using (memorystream stream = new memorystream())     {         using (stream deflate = usedeflate             ? (stream)new deflatestream(stream, compressionmode.compress, true)             : (stream)new gzipstream(stream, compressionmode.compress, true))         using (streamwriter writer = new streamwriter(deflate))             writer.write(response);         compressed = new byte[stream.length];         stream.position = 0;         stream.read(compressed, 0, compressed.length);     }     response.headers["content-encoding"] = usedeflate ? "deflate" : "gzip";     response.binarywrite(compressed); } 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -