#StackBounty: #c# #asp.net #gzip #response #http-compression Compress the Response has no effect

Bounty: 200

I want to zipping response in my Asp.Net web site. and I wrote this code:

public static void CompressPage(HttpRequest Request, HttpResponse Response)
{
    string acceptEncoding = Request.Headers["Accept-Encoding"];
    Stream prevUncompressedStream = Response.Filter;

    if (acceptEncoding.IsEmpty())
    {
        return;
    }

    acceptEncoding = acceptEncoding.ToLower();

    if (acceptEncoding.Contains("gzip"))
    {
        Response.Filter = new GZipStream(prevUncompressedStream, CompressionMode.Compress);
        Response.AppendHeader("Content-Encoding", "gzip");
    }
    else if (acceptEncoding.Contains("deflate"))
    {
        Response.Filter = new DeflateStream(prevUncompressedStream, CompressionMode.Compress);
            Response.AppendHeader("Content-Encoding", "deflate");
    }
}

and call it it Page_Load event:

protected void Page_Load(object sender, EventArgs e)
{
    ...
    ZipHtmlPage.CompressPage(Request, Response);
}

The problem is when I run the code with and without above code in Page_Load the size of response does not change.

enter image description here

Where is the problem?

Thanks


Edit 1)

I think that "Content-Encoding", "gzip" doesn’t add to header:

enter image description here

I don’t know why?


Edit 2)

When I use HttpModule for doing http compression:

public class CompressModule : IHttpModule
{
    public void Init(HttpApplication application)
    {
        application.BeginRequest += (new EventHandler(this.Application_BeginRequest));
    }

    private void Application_BeginRequest(Object source, EventArgs e)
    {
        HttpContext context = HttpContext.Current;
        context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress);
        HttpContext.Current.Response.AppendHeader("Content-Encoding", "gzip"); 
    }
    public void Dispose()
    {
    }
}

I got this in every pages:

enter image description here


Get this bounty!!!

#StackBounty: #c# #asp.net #sql-server #sql-server-2012 #sqlcachedependency Simple SqlCacheDependency

Bounty: 50

Almost every tutorial I have read seems to incorrectly setup SqlCacheDependency. I believe they normally mix up the outdated polling method with the query notification method.

Here are two of many examples:

https://www.codeproject.com/Tips/787483/Web-Caching-with-SqlCacheDependency-Simplified (non-microsoft)

https://docs.microsoft.com/en-us/dotnet/api/system.web.caching.sqlcachedependency?view=netframework-4.8 (Microsoft)


Based on my testing, if you are using the broker (MSSQL 2015+) you don’t need to make any .config changes nor do you need to make any SqlCacheDependencyAdmin calls (Don’t need to define tables, etc).

I simplify just do this…

SqlDependency.Start(connString)
...
queryString = "SELECT ...";
cacheName = "SqlCache" + queryString.GetHashCode();
...
using (var connection = new SqlConnection(connString))
{
    connection.Open();
    var cmd = new SqlCommand(queryString, connection)
    {
        Notification = null, 
        NotificationAutoEnlist = true
    };

    var dependency = new SqlCacheDependency(cmd);

    SqlDataReader reader = cmd.ExecuteReader();
    try
    {
        while (reader.Read())
        {
            // Set the result you want to cache
            data = ...
        }
    }
    finally
    {
        reader.Close();
    }

    HostingEnvironment.Cache.Insert(cacheName, data, dependency);
}

(The code that checks if the cache is null or not is not included, as thats all just setup. I just want to show the setting of the cache)

This seems to work without the need to define which tables are involved in the query and make complicated triggers on each table. It just works.

More surprising to me is that the rules for making a query have notification : https://docs.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/ms181122(v=sql.105) (Can’t find documentation newer than 2008) don’t seem to apply. I purpose do a TOP in my SQL and it still works.

For a test I have it run a query 1000 times involving a table named “Settings”. Then I update a value in the table and repeat the query.

I watch the Profiler for any queries involving the word “Settings” and I see the query is executed just 1 time (to set the cache) and then the update statement occurs, and then the query is re-executed one more time (the cache was invalidated and the query ran again)

I am worried that in my 2-3 hours of struggling with the proper way to do this I am missing something and it really is this simple?

Can I really just put any query I want and it’ll just work? I am looking for any pointers where I am doing something dangerous/non-standard or any small print that I am missing


Get this bounty!!!

#StackBounty: #javascript #asp.net #paypal How does PayPal disable your browser's toolbar access when you ue the new Checkout buttons

Bounty: 50

When you click on the PayPal Button in v2 of the API, the browser’s toolbar etc is also greyed out and not accessible. It is re-enabled when the PayPal process finishes. The actions are the same as if it was a modal popup BUT it applies to the whole browser.

Presumably this is a function built into the PayPal API but I didn’t think this was possible but it obviously is.

Anyone know the script to do this?


Get this bounty!!!

#StackBounty: #cookies #asp.net #web-authentication #session Why are ASP.NET form authentication cookies deleted only on client side if…

Bounty: 50

ASP.NET documentation says:

FormsAuthentication.SignOut()

Removes the forms-authentication ticket from the browser

Why is the cookie not invalidated at the server as well? It would be easy to implement. After all this code runs at the server. In fact it’s easier to implement on the server because the server trusts itself, whereas clearing the cookies on the client requires cooperation by the client. What if the client fails to cooperate by error or maliciously? What then?

I tested this code and it does what it says. It removes the cookie on the browser, and it leaves the server side cookie valid. I took a copy of the cookie prior to signing out, and then signed myself back in with that cookie without providing username and password.

So what’s the worse that could happen? This:

  1. Bob is logged in and saves his session cookie to notepad
  2. Administrator wants to revoke Bob’s access immediately and sets a flag that triggers FormsAuthentication.SignOut() on the next web request from Bob. The administrator also changes Bob’s password.
  3. Bob’s browser reacts to SignOut() by clearing his cookie and he is signed out imediatelly. Bob sees a message “you have been signed out”, he tries to hit the back button but he is really signed out. He can’t get back in. He tries logging in with his username and password, but it says his password is invalid.
  4. Administrator watches server logs and sees that SignOut() was executed successfully.
  5. Bob uses saved session cookie to log back in (and is allowed). He continues working on the system indefinitely.

Isn’t this a bad thing? Is this just ASP.NET or do other frameworks do it this way?


Get this bounty!!!

#StackBounty: #shared-folders #asp.net #iis-6 Web application failing to map a shared drive

Bounty: 50

I’ve got a web application which uses in its code behind net use in order to map a net work drive that is shared on a different server and then it writes data onto the mapped drive.

This worked fine in the past. After a long break now whenever I try to map the drive I get “access denied to path blabluppblub…”.

The exact command I’m using is: net use \blabluppblub mypass /user:myuser

When I connect to the server with my admin account and type the commands in manually….it works without a hitch. So I guess it is some sort of user permissions problem. But I don’t find out where it could stem from.

What is more is that the identity used is the: ApplicationPoolIdentity.

So the question is: Is there any way to find out what the exact problem all of a sudden is and how could I solve it?


Get this bounty!!!

#StackBounty: #asp.net #adsense Ads doesn't appear after removing and adding again

Bounty: 100

The ads not appear after I have removed and re-added the Adsense code.
How can I fix this ? Thanks

I use the default code as,

//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js
<ins class="adsbygoogle"
 style="display:block"
 data-ad-client="ca-pub-myid"
 data-ad-slot="id2"
 data-ad-format="auto"
 data-full-width-responsive="true"></ins>

    (adsbygoogle = window.adsbygoogle || []).push({});


Get this bounty!!!

#StackBounty: #c# #asp.net #signalr #signalr-hub #asp.net-core-2.1 How to catch ASP.NET Core 2 SignalR exceptions on server-side and ha…

Bounty: 50

Context: There are differences between ASP.NET SignalR and ASP.NET Core SignalR you can read here.

As described in this stackoverflow post in ASP.NET SignalR you can catch unhandled exceptions on server side via the HubPipelineModule which not exists in ASP.NET Core SignalR.

How can we catch unhandled exceptions and pass them to the client side in ASP.NET Core SignalR?

JavaScript code (client):

var hub = null;

var initWebSocket = function () {

    hub = new signalR.HubConnectionBuilder().withUrl("/MyHub").build();

    hub.on("ReceiveMessage", function (pMessage) {

        [...]
    });

    hub.start().catch(function (err) {
        return console.error(err.toString());
    });
};

var executeWebsocketTestException = function () {

    // send to server
    hub.invoke("TestException").catch(function (exception) {

        if(exception.type)
        {
            ...
        }
    });
};

ASP.NET Core 2 Hub (server):

public class MyHub : Hub
{
    public async Task TestException()
    {
        throw new SignalRTest.Exceptions.TestException("This is a Websocket Test Exception.");
    }
}


Get this bounty!!!