TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sharma Raushan
NA
527
15.2k
Gzip compression with code in asp.net mvc.
Aug 9 2020 8:32 AM
I have shared plesk hosting and have very less access priveleges to IIS configuration , so to enable Gzip compression i followed one of the post discussed here,
https://www.c-sharpcorner.com/Forums/gzip-compression-issue-on-iis-85
and implemented the below action filter
public
class
CompressAttribute:ActionFilterAttribute
{
public
override
void
OnResultExecuting(ResultExecutingContext filterContext)
{
HttpRequestBase request = filterContext.HttpContext.Request;
string acceptEncoding = request.Headers[
"Accept-Encoding"
];
if
(string.IsNullOrEmpty(acceptEncoding))
return
;
acceptEncoding = acceptEncoding.ToUpperInvariant();
HttpResponseBase response = filterContext.HttpContext.Response;
if
(acceptEncoding.Contains(
"GZIP"
))
{
response.AppendHeader(
"Content-encoding"
,
"gzip"
);
response.Filter =
new
GZipStream(response.Filter, CompressionMode.Compress);
}
else
if
(acceptEncoding.Contains(
"DEFLATE"
))
{
response.AppendHeader(
"Content-encoding"
,
"deflate"
);
response.Filter =
new
DeflateStream(response.Filter, CompressionMode.Compress);
}
}
}
This is very good when we don't have access to IIS, but the problem is it works only for Html.
How to compress CSS and Javascript with this approach?or is there any other approach?
Reply
Answers (
7
)
vb.net arrays and sorting of array
How do we authorize static file in asp.net mvc?