示例 - 如何在ASP.NET中应用Spider Studio生成的DLL?
>> 接前文 "示例 - 如何在Console应用程序中应用SpiderStudio生成的DLL?", 将其运用到ASP.NET中:
1. 创建WebApplication项目, 引入www.utilities_online.info.XmlJsonConverter.dll
2. 设置Target Framework为: .NET Framework 4
3. 在Default.aspx上拖放控件
HTML:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" AspCompat="true" %> <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> </asp:Content> <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <table> <tr><td>XML</td><td></td><td>JSON</td></tr> <tr> <td> <input id="xml" style="width:445px;height:320px" type="text" runat=server/> </td> <td> <asp:Button ID="toxml" runat="server" Text="<-" onclick="toxml_Click" /> <br /> <asp:Button ID="tojson" runat="server" Text="->" onclick="tojson_Click" /> </td> <td> <input id="json" style="width:445px;height:320px" type="text" runat=server /> </td> </tr> </table> </asp:Content>
4. 将Default.aspx设置为: AspCompat="true"
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" AspCompat="true" %>
- 这样做的目的是将页面的线程模型改成单线程模式, 从而能够支持activeX控件的调用.
5. 编写后台代码
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using www.utilities_online.info; namespace WebApplication1 { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void toxml_Click(object sender, EventArgs e) { xml.Value = new XmlJsonConverter().Json2Xml(json.Value); } protected void tojson_Click(object sender, EventArgs e) { json.Value = new XmlJsonConverter().Xml2Json(xml.Value); } } }
6. 运行~!
相关阅读: