I made custom HttpModule which searches for $where param, changes it (replaces DateTime.Now with DateTime.UtcNow) and rewrites path. Simplified module implementation looks like:
private void OnBeginRequest(object sender, EventArgs e)
{
HttpApplication app = sender as HttpApplication;
string whereQuery = app.Request.QueryString["$where"];
string newWhereQuery = this.ChangeWhereQuery(whereQuery);
// Combine new where query string with other query strings
string newQueryString = this.BuildQueryString(app, newWhereQuery);
app.Context.RewritePath(app.Request.FilePath, app.Request.PathInfo, newQueryString);
}
Problem is that after rewriting query expression is lost, i.e. in DomainService’s Query method queryDescription.Query is null:
public override IEnumerable Query(QueryDescription queryDescription, out IEnumerable<ValidationResult> validationErrors, out int totalCount)
{
// queryDescription.Query is null
return base.Query(queryDescription, out validationErrors, out totalCount);
}
If I replace my custom module with following code (path is rewritten with original query string), everything works fine:
private void OnBeginRequest(object sender, EventArgs e)
{
HttpApplication app = sender as HttpApplication;
string qs = app.Request.QueryString.ToString();
app.Context.RewritePath(app.Request.FilePath, app.Request.PathInfo, qs);
}
I found this post on Silverlight forum, but thread URL is not available any more:
WCF RIA Services itself uses URL rewriting so it can have conflicts. Here was a recent thread with a solution: http://forums.silverlight.net/forums/p/233310/573340.aspx#573340
Any ideas why is query expression lost after changing URL query string?
I’m using WCF RIA Services V1.0 SP2, .NET 4 and IIS 7.