Archive
Latest jQuery
For those that always wants to use the latest jQuery, here’s the link
Effects of MS11-100 on asp.net websites
On 29 Dec 2011, Microsoft released a security bulletin MS11-100 which attempts to resolve hash collisions vulnerabilities found in asp.net.
However if you have form pages with > 1000 elements, then you will encounter the following error (for asp.net)
System.Web.HttpException (0×80004005): The URL-encoded form data is not valid. —> System.InvalidOperationException: Operation is not valid due to the current state of the object.
at System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded()
at System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding)
at System.Web.HttpRequest.FillInFormCollection()
at System.Web.HttpRequest.FillInFormCollection()
at System.Web.HttpRequest.get_Form()
at System.Web.HttpRequest.get_HasForm()
at System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull)
at System.Web.UI.Page.DeterminePostBackMode()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
What is happening is that asp.net is now checking your Form posted data and if it exceeds a certain threshold it will throw the exception above.
To workaround this, what you can do is to put the following item inside appsettings
<add key="aspnet:MaxHttpCollectionKeys" value="10000" />
By default this value is 1000, but you are free to either limit or give it a larger value
ASP.NET 3.x and above: creating dynamic, or anonymous types
A relatively unknown feature in available since .NET 3.0 is the ability to create dynamic or more correctly anonymous types .
These are typically used in LINQ select scenarios
from p in db.Users
select new (p.Name, p.Email}
This basically creates an anonymous type with Name and Email properties.
With all the new advancements in web technologies, there is this increasing need to have the ability to create objects on the fly so as to pass to web api or to send data across different systems.
Creating an anonymous object in code is pretty simple, below is an example of how you create one
var obj = new {ID=1, Name=”Jeffery”, Email=”a@a.com”};
This basically creates a new object on the fly with the following 3 properties
- ID
- Name
- For more reading, look at the following links:
http://msdn.microsoft.com/en-us/library/bb308966.aspx#csharp3.0overview_topic15
SignalR–Configuring timeout for connections
Based on the SignalR wiki, in order to make SignalR work with Azure or load balancers, you will need to tune it such that the polling timeout is lesser than the default polling time of 110 seconds.
To do this, the wiki at https://github.com/SignalR/SignalR/wiki/Configuring-SignalR tells you to do the following
ASP.NET Example (Global.asax)
var config = AspNetHost.DependencyResolver.Resolve<IConfigurationManager>(); config.ReconnectionTimeout = TimeSpan.FromSeconds(25);
However if you were to just copy and paste that, you will find that visual studio reports the following 2 errors and wurlies on your code
The name ‘AspNetHost’ does not exist in the current context
and
The type or namespace name ‘IConfigurationManager’ could not be found (are you missing a using directive or an assembly reference?)
Actually what happens is that the wiki actually forgot to mention that you will actually need to import a few namespaces to global.asax.
They are
- SignalR.Configuration – Fixes the IConfigurationManager
- SignalR.Hosting.AspNet – Fixes AspNetHost
- SignalR.Infrastructure – This is where the Resolve extension reside
- So after adding all these, your global.asax will look like
<%@ Application Language="C#" %>
<%@ Import Namespace="SignalR.Configuration" %><%@ Import Namespace="SignalR.Hosting.AspNet" %>
<%@ Import Namespace="SignalR.Infrastructure" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startupvar config = AspNetHost.DependencyResolver.Resolve<IConfigurationManager>();
config.ReconnectionTimeout = TimeSpan.FromSeconds(25);
}
</script>
Enjoy!