views:

20

answers:

2

If some specific request coming to MVC web site, e.g status.aspx how i may dynamically create a response e.g "Server1 OK" without creating any additional controllers to process this request.

We have web farm and each of the sites should response " OK" when status.aspx requested.

Or i should create for example controller Status and redirect to this controller if status.aspx requested. In such case question is how i may redirect from to Status when status.aspx requested.

+1  A: 

In your ActionResult you can inject the response header. This can be done on any existing controller.

Imports System.Web.Mvc
Imports System.Net

Namespace Controllers
    Public Class MyFunkyController: Inherits MyApp.Core.Base.BaseController

        Function Index() As ActionResult
            Response.StatusCode = CInt(HttpStatusCode.OK)
            Return View()
        End Function

        Function Foo() As ActionResult
            Response.StatusCode = CInt(HttpStatusCode.OK)
            Return View()
        End Function

        Function Bar() As ActionResult
            Response.StatusCode = CInt(HttpStatusCode.OK)
            Return View()
        End Function

    End Class
End Namespace

Alternatively you can set this in your BaseController (but I wouldn't recommend it)

    Protected Overrides Function CreateActionInvoker() As System.Web.Mvc.IActionInvoker
            Response.StatusCode = CInt(HttpStatusCode.OK)
    End Function
rockinthesixstring
PS: sorry for the VB, but the principles are the same. Just use http://converter.telerik.com to get the CSharp version.
rockinthesixstring
How i may check that request for status.aspx comes and request it to controller?
Macaron
Can you better explain the problem that you're having? I don't fully understand why you need to send the Status Code down the line.
rockinthesixstring
A: 

You should take a look at a feature called Routing. It allows you to map request URLs to controllers that are meant to process the response.

marcind