Serializing .NET Resources (.resx) as JSON (part 2)

So after playing with my own code after a while I realized that there was a slight flaw in my thinking.  Since every application is slightly different in the way it determines what culture to use, and that each request is technically a different Thread, I need a more generic way to capture that information.

I decided to use a querystring value.  Here is my updated code in regards to reading the querystring culture, setting it and fired up the appropriate ResourceManager..

 

ResourceManager rm = new ResourceManager(ConfigurationManager.AppSettings["JSResourcesAssemblyType"].ToString(),
                Assembly.LoadFile(ConfigurationManager.AppSettings["JSResourcesAssemblyPath"].ToString()));
            if (context.Request.QueryString["CultureCode"] == null) return;
            var culture = context.Request.QueryString["CultureCode"].ToString();            
            ResourceSet rs = rm.GetResourceSet(new CultureInfo(culture), true, true);            
            var sbInitial = "var rm = {";
            var sb = new StringBuilder(sbInitial);            
            var resEnum = rs.GetEnumerator();
            while (resEnum.MoveNext())
            {
                if (sb.ToString() != sbInitial) sb.Append(",");
                sb.Append("\"" + resEnum.Key + "\":\"" + 
                    resEnum.Value.ToString().Replace("\r\n", "").Replace("\"", "\\\"") + "\"");
            }
 
            sb.Append("}");
            sb.ToString();
 
            context.Response.ContentType = "text/javascript";
            context.Response.Write(sb.ToString());
06.09.2011 09:36 by Danny Gershman | Comments (0) | Permalink

Enabling ASP Errors on Vista/Windows 7 (IIS7-7.5)

Pretty tricky, the title says it all

cscript %systemdrive%\inetpub\adminiscripts\adsutil.vbs set w3svc/AspScriptErrorSentToBrowser true      (to allow error message send to client)

On a x64 OS (I run Windows 7 RC x64)

cscript C:\Windows\winsxs\amd64_microsoft-windows-iis-legacyscripts_31bf3856ad364e35_6.1.7100.0_none_4b5800ce84aa413c\adsutil.vbs set w3svc/AspScriptErrorSentToBrowser true

08.13.2009 09:27 by Danny Gershman | Comments (0) | Permalink