I'd like to detect requests made by my Silverlight client in ASP.Net MVC. Silverlight can't set 'X-Requested-With' as far as I remember. What do I use instead?
that would be a nice choice for a custom header. :-)
andreas
2010-03-10 12:44:21
+1
A:
You could probably just make your own header (like X-This-Is-Silverlight=true or something). And then you'd only need to check for that header in your mvc-application (shouldn't be to hard). If not you can allways add a querystring-parameter (like mysite.com/home?issilverlight=true), but then it could be forged with the browser pretty easy.
Also, you could try to use Http Put (or something other than get or post) because normal browsers don't do that.
Alxandr
2010-03-10 12:23:27
thanks. A custom header like request.Headers["x-custom-header"] = "value"; might do it. Do you know how to check in on server side if the header is set?
andreas
2010-03-10 12:43:02
http://dotnetperls.com/request-headers-aspnetbool issilverlight = Request.Headers.Keys.Contains("x-custom-header"); (havn't tried out...)
Alxandr
2010-03-10 12:50:52