<p>I'm using BlogEngine.NET (a fine, fine tool) and I was playing with the TinyMCE editor and noticed that there's a place for me to create a list of external links, but it has to be a javascript file:</p>

<p><code>external_link_list_url : "example_link_list.js"</code></p>

<p>this is great, of course, but the list of links I want to use needs to be generated dynamically from the database. This means that I need to create this JS file from the server on page load.  Does anyone know of a way to do this? Ideally, I'd like to just overwrite this file each time the editor is accessed.</p>

<p>Thanks!</p>

[{'answer_id': 68117, 'author': 'mjallday', 'author_id': 6084, 'author_profile': 'https://Stackoverflow.com/users/6084', 'pm_score': 0, 'selected': False, 'text': '<p>If you can\'t change the file extension (and just return plain text, the caller shouldn\'t care about the file extension, js is plain text) then you can set up a handler on IIS (assuming it\'s IIS) to handle javascript files.</p>\n\n<p>See this link - <a href="http://msdn.microsoft.com/en-us/library/bb515343.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/bb515343.aspx</a> -  for how to setup IIS 6 within windows to handle any file extension. Then setup a HttpHandler to receive requests for .js (Just google httphandler and see any number of good tutorials like this one: <a href="http://www.devx.com/dotnet/Article/6962/0/page/3" rel="nofollow noreferrer">http://www.devx.com/dotnet/Article/6962/0/page/3</a> )</p>\n'}, {'answer_id': 68132, 'author': 'JustAsItSounds', 'author_id': 10586, 'author_profile': 'https://Stackoverflow.com/users/10586', 'pm_score': 2, 'selected': False, 'text': '<p>I would create an HTTPHandler that responds with the desired data read from the db. Just associate the HTTPHandler with the particular filename \'example_link_list.js\' in your web-config. Make sure you set </p>\n\n<pre><code>context.Response.ContentType = "text/javascript";\n</code></pre>\n\n<p>then just context.Response.Write(); your list of external links</p>\n'}, {'answer_id': 68518, 'author': 'Wayne', 'author_id': 8236, 'author_profile': 'https://Stackoverflow.com/users/8236', 'pm_score': 0, 'selected': False, 'text': '<p>Just point it at an aspx file and have that file spit out whatever javascript you need.  I did this recently with TinyMCE in PHP and it worked like a charm.</p>\n\n<p>external_link_list_url : "example_link_list.aspx"</p>\n\n<p>In your aspx file:</p>\n\n<pre>&lt;%@ Page Language="C#" AutoEventWireup="false" CodeFile="Default.aspx.cs" Inherits="Default" %&gt;</pre>\n\n<p>in your code-behind (C#):</p>\n\n<pre>\nusing System;\n\npublic partial class Default : System.Web.UI.Page\n{\n    protected void Page_Load(object sender, EventArgs e)\n    {\n        Response.Write("var tinyMCELinkList = new Array(");\n        // put all of your links here in the right format..\n        Response.Write(string.Format("[\'{0}\', \'{1}\']", "name", "url"));\n        Response.Write(");");\n    }\n}\n</pre>\n'}, {'answer_id': 68831, 'author': 'JustAsItSounds', 'author_id': 10586, 'author_profile': 'https://Stackoverflow.com/users/10586', 'pm_score': 1, 'selected': False, 'text': '<p>if your 3rd party code doesn\'t require that the javascript file has the .js extension, then you can create your HTTPHandler and map it to either .axd or .ashx extension in web.config only - no need to change IIS settings as these extensions are automatically configured by IIS to be handled by asp.net.</p>\n\n<pre><code>&lt;system.web&gt;\n  &lt;httpHandlers&gt;\n    &lt;add verb="*" path="example_link_list.axd" type= "MyProject.MyTinyMCE, MyAssembly" /&gt;\n  &lt;/httpHandlers&gt;\n&lt;/system.web&gt;\n</code></pre>\n\n<p>This instructs IIS to pass all requests for \'example_link_list.axd\' (via POST and GET) to the ProcessRequest method of MyProject.MyTinyMCE class in MyAssembly assembly (the name of your .dll)</p>\n\n<p>You could alternatively use Visual Studio\'s \'Generic Handler\' template instead - this will create an .ashx file and code-behind class for you. No need to edit web.config either.</p>\n\n<p>using an HTTPHandler is preferrable to using an .aspx page as .aspx requests have a lot more overheads associated (all of the page events etc.)</p>\n'}]
['https://Stackoverflow.com/questions/68067', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7173/']