Navigation Menu

Skip to content

Commit

Permalink
[asp.net] Part of fix for bug #649546. A partial rewrite of the web/s…
Browse files Browse the repository at this point in the history
…cript resource handler.

   Backport of commit a9cb57c

    * System.Web/System.Web.Handlers/AssemblyResourceLoader.cs: AssemblyResourceLoader/ScriptResourceHandler must
      always generate the same URL for every assembly+resource pair, or otherwise the browser would re-fetch
      the resource in situations where it is not desired (e.g. during an async request to the server to update
      a panel).
      The generated URLs are not encrypted using real encryption, just hashed.
      In addition, the handler code got modernized a bit.

    * System.Web.Extensions/System.Web.UI/ScriptManager.cs: scriptStartupBlock is a 3.5+ thing

    * System.Web.Extensions_1.0/Makefile: use the 1.0 Microsoft AJAX library for this compat assembly

    * System.Web/System.Web.Util/MachineKeySectionUtils.cs: made GetValidationKey public
  • Loading branch information
grendello committed Nov 30, 2010
1 parent ae4cf60 commit 5a7ee43
Show file tree
Hide file tree
Showing 13 changed files with 286 additions and 552 deletions.
Expand Up @@ -62,7 +62,9 @@ public class ScriptManager : Control, IPostBackDataHandler, IScriptManager
const string hiddenField = "hiddenField";
const string arrayDeclaration = "arrayDeclaration";
const string scriptBlock = "scriptBlock";
#if NET_3_5
const string scriptStartupBlock = "scriptStartupBlock";
#endif
const string expando = "expando";
const string onSubmit = "onSubmit";
const string asyncPostBackControlIDs = "asyncPostBackControlIDs";
Expand Down Expand Up @@ -1339,12 +1341,14 @@ void RegisterPanelForRefresh (UpdatePanel panel)
else
WriteCallbackOutput (output, scriptBlock, scriptContentWithTags, SerializeScriptBlock (scriptEntry));
break;
#if NET_3_5
case RegisteredScriptType.ClientStartupScript:
if (scriptEntry.AddScriptTags)
WriteCallbackOutput (output, scriptStartupBlock, scriptContentNoTags, scriptEntry.Script);
else
WriteCallbackOutput (output, scriptStartupBlock, scriptContentWithTags, SerializeScriptBlock (scriptEntry));
break;
#endif
case RegisteredScriptType.ClientScriptInclude:
WriteCallbackOutput (output, scriptBlock, scriptPath, scriptEntry.Url);
break;
Expand Down
13 changes: 7 additions & 6 deletions mcs/class/System.Web.Extensions_1.0/Makefile
Expand Up @@ -8,12 +8,12 @@ LIBRARY_NAME = System.Web.Extensions.dll
LIBRARY_COMPAT = yes

RESOURCE_FILES= \
../MicrosoftAjaxLibrary/System.Web.Extensions/3.5.0.0/3.5.21022.8/MicrosoftAjax.debug.js \
../MicrosoftAjaxLibrary/System.Web.Extensions/3.5.0.0/3.5.21022.8/MicrosoftAjax.js \
../MicrosoftAjaxLibrary/System.Web.Extensions/3.5.0.0/3.5.21022.8/MicrosoftAjaxTimer.debug.js \
../MicrosoftAjaxLibrary/System.Web.Extensions/3.5.0.0/3.5.21022.8/MicrosoftAjaxTimer.js \
../MicrosoftAjaxLibrary/System.Web.Extensions/3.5.0.0/3.5.21022.8/MicrosoftAjaxWebForms.debug.js\
../MicrosoftAjaxLibrary/System.Web.Extensions/3.5.0.0/3.5.21022.8/MicrosoftAjaxWebForms.js
../MicrosoftAjaxLibrary/System.Web.Extensions/1.0.61025.0/MicrosoftAjax.debug.js \
../MicrosoftAjaxLibrary/System.Web.Extensions/1.0.61025.0/MicrosoftAjax.js \
../MicrosoftAjaxLibrary/System.Web.Extensions/1.0.61025.0/MicrosoftAjaxTimer.debug.js \
../MicrosoftAjaxLibrary/System.Web.Extensions/1.0.61025.0/MicrosoftAjaxTimer.js \
../MicrosoftAjaxLibrary/System.Web.Extensions/1.0.61025.0/MicrosoftAjaxWebForms.debug.js\
../MicrosoftAjaxLibrary/System.Web.Extensions/1.0.61025.0/MicrosoftAjaxWebForms.js

RESOURCE_FILES_DIST= \
../MicrosoftAjaxLibrary/System.Web.Extensions/3.5.0.0/3.5.21022.8/MicrosoftAjax.debug.js \
Expand All @@ -34,6 +34,7 @@ LIB_MCS_FLAGS = \
-define:SYSTEM_WEB_EXTENSIONS \
-r:$(corlib) \
-r:System.dll \
-r:System.Core.dll \
-r:System.Drawing.dll \
-r:System.Data.dll \
-r:System.Xml.dll \
Expand Down
Expand Up @@ -39,12 +39,6 @@ enum MachineKeyValidation
SHA1 = 1,
TripleDES = 2,
AES = 3,
#if NET_4_0
HMACSHA256 = 4,
HMACSHA384 = 5,
HMACSHA512 = 6,
Custom = 7
#endif
}
}

Expand Up @@ -47,9 +47,6 @@ public sealed class MachineKeySection : ConfigurationSection
static ConfigurationProperty validationKeyProp;
static ConfigurationPropertyCollection properties;
static MachineKeyValidationConverter converter = new MachineKeyValidationConverter ();
#if NET_4_0
MachineKeyValidation validation;
#endif

static MachineKeySection ()
{
Expand All @@ -61,17 +58,10 @@ static MachineKeySection ()
PropertyHelper.WhiteSpaceTrimStringConverter,
PropertyHelper.NonEmptyStringValidator,
ConfigurationPropertyOptions.None);
#if NET_4_0
validationProp = new ConfigurationProperty ("validation", typeof (string), "HMACSHA256",
PropertyHelper.WhiteSpaceTrimStringConverter,
PropertyHelper.NonEmptyStringValidator,
ConfigurationPropertyOptions.None);
#else
validationProp = new ConfigurationProperty ("validation", typeof (MachineKeyValidation),
MachineKeyValidation.SHA1, converter,
PropertyHelper.DefaultValidator,
ConfigurationPropertyOptions.None);
#endif
validationKeyProp = new ConfigurationProperty ("validationKey", typeof (string), "AutoGenerate,IsolateApps",
PropertyHelper.WhiteSpaceTrimStringConverter,
PropertyHelper.NonEmptyStringValidator,
Expand All @@ -88,19 +78,6 @@ static MachineKeySection ()
Config.AutoGenerate (MachineKeyRegistryStorage.KeyType.Validation);
}

#if NET_4_0
public MachineKeySection ()
{
// get DefaultValue from ValidationAlgorithm
validation = (MachineKeyValidation) converter.ConvertFrom (null, null, ValidationAlgorithm);
}

[MonoTODO]
public MachineKeyCompatibilityMode CompatibilityMode {
get; set;
}
#endif

protected override void Reset (ConfigurationElement parentElement)
{
base.Reset (parentElement);
Expand Down Expand Up @@ -132,45 +109,12 @@ protected override void Reset (ConfigurationElement parentElement)
}
}

#if NET_4_0
// property exists for backward compatibility
public MachineKeyValidation Validation {
get { return validation; }
set {
if (value == MachineKeyValidation.Custom)
throw new ArgumentException ();

string algo = value.ToString ();
// enum and accept values differs for TripleDES
ValidationAlgorithm = (algo == "TripleDES") ? "3DES" : algo;
}
}

[StringValidator (MinLength = 1)]
[TypeConverter (typeof (WhiteSpaceTrimStringConverter))]
[ConfigurationProperty ("validation", DefaultValue = "HMACSHA256")]
public string ValidationAlgorithm {
get { return (string) base [validationProp];}
set {
if (value == null)
return;

if (value.StartsWith ("alg:"))
validation = MachineKeyValidation.Custom;
else
validation = (MachineKeyValidation) converter.ConvertFrom (null, null, value);

base[validationProp] = value;
}
}
#else
[TypeConverter (typeof (MachineKeyValidationConverter))]
[ConfigurationProperty ("validation", DefaultValue = "SHA1")]
public MachineKeyValidation Validation {
get { return (MachineKeyValidation) base [validationProp];}
set { base[validationProp] = value; }
}
#endif

[TypeConverter (typeof (WhiteSpaceTrimStringConverter))]
[StringValidator (MinLength = 1)]
Expand Down
Expand Up @@ -39,11 +39,7 @@ namespace System.Web.Configuration {

public sealed class MachineKeyValidationConverter : ConfigurationConverterBase
{
#if NET_4_0
const string InvalidValue = "The enumeration value must be one of the following: SHA1, MD5, 3DES, AES, HMACSHA256, HMACSHA384, HMACSHA512.";
#else
const string InvalidValue = "The enumeration value must be one of the following: SHA1, MD5, 3DES, AES.";
#endif
public MachineKeyValidationConverter ()
{
}
Expand All @@ -59,30 +55,17 @@ public override object ConvertFrom (ITypeDescriptorContext ctx, CultureInfo ci,
return MachineKeyValidation.TripleDES;
case "AES":
return MachineKeyValidation.AES;
#if NET_4_0
case "HMACSHA256":
return MachineKeyValidation.HMACSHA256;
case "HMACSHA384":
return MachineKeyValidation.HMACSHA384;
case "HMACSHA512":
return MachineKeyValidation.HMACSHA512;
#endif
default:
throw new ArgumentException (InvalidValue);
}
}

public override object ConvertTo (ITypeDescriptorContext ctx, CultureInfo ci, object value, Type type)
{
#if NET_4_0
if ((value == null) || (value.GetType () != typeof (MachineKeyValidation)))
throw new ArgumentException (InvalidValue);
#else
if (value.GetType () != typeof (MachineKeyValidation)) {
/* MS throws this exception on an invalid */
throw new FormatException (InvalidValue);
}
#endif

switch ((MachineKeyValidation) value) {
case MachineKeyValidation.MD5:
Expand All @@ -93,21 +76,9 @@ public override object ConvertTo (ITypeDescriptorContext ctx, CultureInfo ci, ob
return "3DES";
case MachineKeyValidation.AES:
return "AES";
#if NET_4_0
case MachineKeyValidation.HMACSHA256:
return "HMACSHA256";
case MachineKeyValidation.HMACSHA384:
return "HMACSHA384";
case MachineKeyValidation.HMACSHA512:
return "HMACSHA512";
default:
// includes MachineKeyValidation.Custom
throw new ArgumentException (InvalidValue);
#else
default:
/* MS throws this exception on an invalid */
throw new FormatException (InvalidValue);
#endif
}
}
}
Expand Down

0 comments on commit 5a7ee43

Please sign in to comment.