1
votes

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.

1

1 Answers

0
votes

The thread I was linking to was probably this one: http://social.msdn.microsoft.com/Forums/en-US/silverlightwcf/thread/c6ab7061-19ce-4bd9-8afe-cfbdc7fd9267/

Looking at your expanded question here though, I think you are trying to hook in at the wrong point. In the DomainService itself, every query comes in through the virtual Query method. If you override the Query method then you should be able to modify the QueryDescription before sending it on to the base.Query method.