進一步去看 fMath 的使用方式如下:
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="850" height="460" id="editML" name="editML" align="middle">
<param name=wmode value="transparent">
<param name="allowScriptAccess" value="sameDomain"/>
<param name="allowFullScreen" value="true"/>
<param name="loop" value="false"/>
<param name="quality" value="high" />
<param name="flashVars" value="configUrl=configMathMLEditor.xml"/>
<param name="movie" value="mathml/MathMLEditor.swf?configUrl=configMathMLEditor.xml" />
<embed src="mathml/MathMLEditor.swf?configUrl=configMathMLEditor.xml"
wmode="transparent"
flashVars="configUrl=configMathMLEditor.xml"
loop="false"
quality="high"
width="850"
height="460"
id="editML"
name="editML"
align="middle"
swliveconnect="true"
allowScriptAccess="sameDomain"
allowFullScreen="true"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer" />
</object>
裡面有提到使用 configMathMLEditor.xml 的地方一共有四個。而我的作法,則是另外寫一隻新的 config.ashx,讓它先去讀取 configMathMLEditor.xml 的原始資料,而這個 xml 裡,已經先將 urlGenerateImage 的值用 $Capture 來取代了。接著再使用取代變數的方式,將 $Capture 以 Web.Config 裡 appSettings 的值來替換。如此,上面提到有4個地方引用了 configMathMLEditor.xml ,就要改成 config.ashx 了,也就是如下:
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="850" height="460" id="editML" name="editML" align="middle">
<param name=wmode value="transparent">
<param name="allowScriptAccess" value="sameDomain"/>
<param name="allowFullScreen" value="true"/>
<param name="loop" value="false"/>
<param name="quality" value="high" />
<param name="flashVars" value="configUrl=config.ashx"/>
<param name="movie" value="mathml/MathMLEditor.swf?configUrl=config.ashx" />
<embed src="mathml/MathMLEditor.swf?configUrl=config.ashx"
wmode="transparent"
flashVars="configUrl=config.ashx"
loop="false"
quality="high"
width="850"
height="460"
id="editML"
name="editML"
align="middle"
swliveconnect="true"
allowScriptAccess="sameDomain"
allowFullScreen="true"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer" />
</object>
最後的重點,就是要撰寫自己的 config.ashx ,簡單的測試程式如下:
<%@ WebHandler Language="C#" Class="config" %>
using System;
using System.Web;
using System.IO;
public class config : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/xml";
Stream iStream = null;
// Identify the file to download including its path.
string filepath =Path.Combine(context.Server.MapPath("./"), "configMathMLEditor.xml");
// Identify the file name.
string filename = System.IO.Path.GetFileName(filepath);
// Open the file.
iStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open,
System.IO.FileAccess.Read, System.IO.FileShare.Read);
//Read Data from FileStream and save to string
StreamReader sRead = new StreamReader(iStream);
string strNewFile = sRead.ReadToEnd();
sRead.Close();
//將變數取代為 web.config 的值
strNewFile = strNewFile.Replace("$Capture", System.Configuration.ConfigurationManager.AppSettings["CaptureUrl"]);
context.Response.Write(strNewFile);
context.Response.Flush();
context.Response.End();
}
public bool IsReusable {
get {
return false;
}
}
}
經過一番打造之後,就可以讓 fMath 裡的設定值,改成去抓 web.Config 了。
參考:
01:response.WriteFile 無法下載大型檔案
02:http://www.fmath.info/
03:FileStream - editing an existing text file

沒有留言:
張貼留言