Dynamically create JS file using ASP.net Handler

I have many clients I want to give them scripts so I want to Create JS file based on their Cusotmer ID.
So I can return and it directly execute on customer side.
Client can be anyone either PHP,Html, ASP.net

Problem is when i browse this link it give me JS string but on customer side this script is not executing like for testing I put alert this alert is not showing on customer side


Customer

<head>
    <script src="https://localhost:12604/JSCreator/Handler.ashx?CustomerID=123" type="text/javascript"></script>
    <title></title>
</head>

Handler file

public class Handler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        string CustomerId = context.Request["CustomerId"].ToString();
        string jscontent = JSFileWriter.GetJS(CustomerId); // This function will return my custom js string

        context.Response.ContentType = "text/javascript";
        context.Response.Write(jscontent);
    }

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

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

ContentType should be application/javascript

public void ProcessRequest(HttpContext context)
{
    string CustomerId = context.Request["CustomerId"].ToString();
    string jscontent = JSFileWriter.GetJS(CustomerId); // This function will return my custom js string

    context.Response.ContentType = "application/javascript";
    context.Response.Write(jscontent);
}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x