Question: I want to create a pretty simple script on the server (A client proxy for server side events).
Whats the most common way of render scripts server side using MVC4?

**Update after first answer:**
I want to include for example `@Scripts.Render("~/eventAggregation/events")` and it should invoke code on my server that generates the Javascript with C# code, also this is for for a lib so I cant do it with a Razor page or MvcController, I want it to be close to SignalR's Hub proxy, I looked at that code but its several hundred lines of codes for injecting a dynamic generated script, must be easier than that?

Answer: 
Since you stated that you cannot use an MvcController or Razor view, you could get closer to the metal: [`IHttpHandler`](http://msdn.microsoft.com/en-us/library/system.web.ihttphandler.aspx). 

So start by writing one:

```
public class MyHandler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        var response = context.Response;
        response.ContentType = "text/javascript";
        var message = "This is some super dynamic message. The UTC time now is: " + DateTime.UtcNow.ToLongTimeString();
        var js = string.Format("alert({0});", new JavaScriptSerializer().Serialize(message));
        response.Write(js);
    }

    public bool IsReusable 
    { 
        get { return true; } 
    }
}

```

then write a corresponding route handler:

```
public class MyHandlerProvider: IRouteHandler
{
    public IHttpHandler GetHttpHandler(RequestContext requestContext)
    {
        return new MyHandler();
    }
}

```

and in your `Application_Start` add a route:

```
protected void Application_Start()
{
    RouteTable.Routes.Add(
        new Route(
            "eventAggregation/events", 
            new MyHandlerProvider()
        )
    );
}

```

And if you didn't want to manually having to add the Route in your `Application_Start` you could use [`WebActivator`](https://github.com/davidebbo/WebActivator). Simply write a static Startup class:

```
internal static class Startup
{
    public static void Application_Start()
    {
        RouteTable.Routes.Add(
            new Route(
                "eventAggregation/events", 
                new MyHandlerProvider()
            )
        );        
    }
}

```

and then use an assembly wide attribute:

```
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(MvcApplication1.Startup), "Application_Start")]

```

And now all that's left in your view is to reference it:

```
<script type="text/javascript" src="~/eventAggregation/events"></script>

```
There are bundles and RenderSection and @Scripts.Render(

example:

```
"@RenderSection("Scripts", true)".

```

Do you wish to pass server side code on down to bleed into your UI layer?

example:

data-attributes or id's to elements and grab them in JavaScript.

```
<div id="MightyId" data-name="@item.attribute"></div>

```

$('#MightyId').data('name')

Or In script tag.

```
var ItemsList = "@item"

```

OR:

```
var Items List = @Html.Raw(Json.Encode(object))  

```