views:

32

answers:

2

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?

+1  A: 

Maybe application/x-silverlight

igor
that would be a nice choice for a custom header. :-)
andreas
+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
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
http://dotnetperls.com/request-headers-aspnetbool issilverlight = Request.Headers.Keys.Contains("x-custom-header"); (havn't tried out...)
Alxandr