开发者

Returning a string from a http GET using asp.net web forms project

I am trying to dynamically generate JavaScript with just a URL get request.

I have accomplished this with asp.net MVC by just returning a string from the action and writing the script tag like this.

<script type='text/javascript' src='script/get/123'></script>

The problem is I need to accomplish the same type of dynamically generated 开发者_JAVA技巧script from a asp.net web forms project.

How would I return dynamiccally generated string with a GET request to a page (or web service) in a asp.net Web Forms project?


You could write a generic handler:

public class CustomJsHandler : System.Web.IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/javascript";
        context.Response.Write("alert('Hello world');");
    }

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

and then specify the address of this handler:

<script type="text/javascript" src="/customjshandler.ashx"></script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜