WebResource.axd 404 Error

Published Thu, Jan 20 2011 1:40 PM

More of a note to self, but this is a brilliant blog post covering a way to decrypt the WebResource.axd parameter string to found out why exactly you are getting a 404 on a WebResource.axd request:

http://blogs.telerik.com/hristodeshev/posts/07-03-26/debugging_asp_net_2_0_web_resources_decrypting_the_url_and_getting_the_resource_name.aspx

And in case that blog dies somewhere in the future, here is the code te decode. Note, this must run in the same website/server as the page where you got the 404.

=======================================

        byte[] encryptedData = HttpServerUtility.UrlTokenDecode(urlEncodedData);

        Type machineKeySection = typeof(MachineKeySection);
        Type[] paramTypes = new Type[] { typeof(bool), typeof(byte[]), typeof(byte[]), typeof(int), typeof(int) };
        MethodInfo encryptOrDecryptData = machineKeySection.GetMethod("EncryptOrDecryptData", BindingFlags.Static | BindingFlags.NonPublic, null, paramTypes, null);

        try
        {
            byte[] decryptedData = (byte[])encryptOrDecryptData.Invoke(null, new object[] { false, encryptedData, null, 0, encryptedData.Length });
            string decrypted = Encoding.UTF8.GetString(decryptedData);

            decryptedLabel.BackColor = Color.Lime;
            decryptedLabel.Text = decrypted;
        }
        catch (TargetInvocationException)
        {
            decryptedLabel.BackColor = Color.Red;
            decryptedLabel.Text = "Error decrypting data. Are you running your page on the same server and inside the same application as the web resource URL that was generated?";
        }

=======================================

 

 

by MarkO
Filed under: , , ,

Comments

# Peter said on Monday, August 01, 2011 4:56 PM

Thanks for this. The original blog post has been removed, and this has just saved me during a moment of webform / webresource hell. Thanks.

# cocktail dresses said on Wednesday, November 30, 2011 2:04 AM

Small hand felt down, Ann now that a bad thing in his sleep still high such as gun.

Leave a Comment

(required) 
(required) 
(optional)
(required) 
Please add 4 and 6 and type the answer here: