[英]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. 我有很多客户想要给他们脚本,所以我想根据客户编号创建JS文件。 So I can return and it directly execute on customer side.
所以我可以退货,它可以直接在客户端执行。 Client can be anyone either PHP,Html, ASP.net
客户端可以是任何人,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 问题是,当我浏览此链接时,它给了我JS字符串,但是在客户端,此脚本未像测试那样执行,我发出了警报,此警报未在客户端显示
Customer 顾客
<head>
<script src="http://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;
}
}
}
ContentType
should be application/javascript
ContentType
应该是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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.