2012-06-07 60 views
2

我有很多客戶我想給他們腳本,所以我想創建基於他們的Cusotmer ID的JS文件。 所以我可以返回並直接在客戶端執行。 客戶端可以是任何人任何PHP,HTML,ASP.net使用ASP.net處理程序動態創建JS文件

問題是當我瀏覽這個鏈接它給我JS字符串,但客戶端此腳本沒有執行類似的測試,我把這個警告警報沒有顯示客戶端


客戶

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

處理程序文件

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; 
     } 
    } 
} 
+2

而問題是什麼? – Andreas

+0

對不起:)我現在更新了問題 –

回答

6

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); 
} 
相關問題