Sunday, June 13, 2010
Practical MongoDB Part 3: Fine Tuning
Thursday, June 10, 2010
Practical MongoDB Part 2: NoRMalized Data Access
Practical MongoDB Part 1: Up and Running
Thursday, April 15, 2010
MVC 2: JsonRequestBehavior DenyGet
This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet.
What the heck?A quick Google turned up a couple articles about MVC 2's new JsonRequestBehavior, and specifically the MSDN article (the link to Haack is dead, so here's a good one). Ok, good to know. I wasn't aware of that vulnerability, but in the mean time I need this project working.
return Json(myjson, JsonRequestBehavior.AllowGet);
protected override JsonResult Json(object data, string contentType,
Encoding contentEncoding, JsonRequestBehavior behavior)
{
// TODO: change all my GET Json request into POST
return base.Json(data, contentType, contentEncoding,
JsonRequestBehavior.AllowGet);
}
IIS 7 (7.5): Hosting Multiple SSL Sites On One IP
Requirements:
- A wild card SSL certificate (of the form *.domain.com). I assume the cert is already installed on your server.
- An IP you wish to use on multiple IIS sites.
- Two or more IIS sites with no SSL binding (I'll touch on changing a binding at the end).
- In an elevated command prompt navigate to
C:\Windows\System32\inetsrv
- Enter the following command (replace {SITENAME}, {IP}, and {HOSTHEADER} with the appropriate values).
appcmd set site /site.name:{SITENAME} /+bindings.[protocol='https',bindingInformation='{IP}:443:{HOSTHEADER}']
- Check the selected cert in IIS via the bindings window. You can change the cert here, but you cannot change the host header.
appcmd set site /site.name:{SITENAME} /bindings.[protocol='https',bindingInformation='{IP}:443:{HOSTHEADER}'].bindingInformation:{NEWIP}:443:{NEWHOSTHEADER}
Wednesday, January 20, 2010
NHibernate: Is That Type a Proxy?
One of our applications does some reflection to map customizable content to domain objects. Anyone familiar with NHibernate and lazy loading has probably encountered proxy classes before. My problem: given a Type, I want the domain type.
It's easy to find out that proxy types extend the domain type they represent, so if I know that my Type is a proxy I can call BaseType to get the domain type. But how do I know if my Type is a proxy?
I tried numerous approaches, but the simplest I found was to look for a specific interface. Turns out proxies implement an interface called INHibernateProxy.
if (clazz.GetInterface(typeof(INHibernateProxy).FullName) != null)
clazz = clazz.BaseType;
Now clazz represents the domain type as desired.
There are other solutions of course, such as detecting the namespace (proxies have none), and possibly checking IsAutoClass (which I couldn't confirm in any documentation). This approach seems the most reliable.
Friday, January 8, 2010
NHibernate: Mapping a Generic List of Enum
I recently ran into a case where I wanted to have a collection of an enumeration on one of my domain classes.
E.g.
public class MyDomainClass
{
public List<MyRoleEnum> Roles { get; set; }
}
But how is do we map something like this in an xml mapping? A quick google didn't turn up the answer, so I played around a bit and found the following works as desired.
<bag name="Roles" table="MyDomainClass2Role">
<key column="MyDomainClassId" />
<element column="Role" type="MyRoleEnum" />
</bag>
To confirm this usage I checked the documentation at hibernate.org. Turns out the <element /> tag was designed for value type bags anyway.