0

这是我的代码它可以正常工作任何人都可以指导我如何改进此代码以制作更好的 HTML 文件以在 CMS 应用程序中使用

请创建名为“图像”的文件夹以正常工作

生成的 HTML 文件将存储在项目文件夹中

 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="HTMLMaker.aspx.cs" Inherits="HTML5Demo.HTMLMaker" ValidateRequest="false"  %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
         <asp:ScriptManager ID="Scriptmanager1" runat="server">
            </asp:ScriptManager>
            <table border="1" cellpadding="5" cellspacing="5">
                <tr>
                    <td colspan="2">
                        <b>HTML Maker</b>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label Text="Title" ID="lblTitle" runat="server" />
                    </td>
                    <td>
                        <asp:TextBox runat="server" ID="txtTitle" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label Text="Image" ID="lblImage" runat="server" />
                    </td>
                    <td>
                        <asp:FileUpload runat="server" ID="fluImage" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label Text="Description" ID="lblDescription" runat="server" />
                    </td>
                    <td>
                        <asp:TextBox runat="server" ID="txtDescription" TextMode="MultiLine" Columns="25"
                            Rows="5" />
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="center">
                        <asp:Button Text="Submit" ID="btnSubmit" OnClick="btnSubmit_Click" runat="server" />
                    </td>
                </tr>
            </table>
    </div>
        </form>
    </body>
    </html>

.cs 文件

using System;
using System.IO;
using System.Text;

 public partial class HTMLMaker : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string ImagePath = string.Empty;
            string ImageName = string.Empty;
            string FileName = Server.MapPath("~/") + txtTitle.Text + ".html";
            if (fluImage.HasFile)
            {
                ImageName = DateTime.Now.ToString("yyyyMMddhhmmss") + Path.GetExtension(fluImage.FileName);
                ImagePath = Server.MapPath("~/Images/") + ImageName;
                fluImage.SaveAs(ImagePath);
            }

            using (FileStream fs = new FileStream(FileName, FileMode.Create))
            {
                using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8))
                {
                    w.WriteLine("<!DOCTYPE html>");
                    w.WriteLine("<html lang=\"en\">");
                    w.WriteLine("<head>");
                    w.WriteLine("<title>" + txtTitle.Text + "</title>");
                    w.WriteLine("</head>");
                    w.WriteLine("<body>");
                    w.WriteLine("<div>");
                    w.WriteLine("<img src='Images/" + ImageName + "' alt=" + fluImage.FileName + "  />");
                    w.WriteLine("</br>");
                    w.WriteLine("<div>");
                    w.WriteLine(txtDescription.Text);
                    w.WriteLine("</div>");
                    w.WriteLine("</div>");
                    w.WriteLine("</body></html>");
                    w.Dispose();
                }
                fs.Dispose();
            }
        }
    }

// 加密 && 解密 // 公共类 EncryptionDecryption {

    public EncryptionDecryption()
    {
    }
    private static string keyString = "552F79D3-1F36-48ab-934C-4629C2274D43";
    private const string strTamperProofKey = "astkvsnanvpi";
    public static string TamperProofStringEncode(string strValue, string strKey)
    {
        System.Security.Cryptography.MACTripleDES mac3des = new System.Security.Cryptography.MACTripleDES();
        System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
        mac3des.Key = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(strKey));
        return System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(strValue)) + System.Convert.ToChar("-") + System.Convert.ToBase64String(mac3des.ComputeHash(System.Text.Encoding.UTF8.GetBytes(strValue)));
    }

    public static string TamperProofStringDecode(string strValue, string strKey)
    {
        String strDataValue = "";
        String strCalcHash = "";
        strValue = strValue.Trim();
        strValue = strValue.Replace(" ", "+");

        System.Security.Cryptography.MACTripleDES mac3des = new System.Security.Cryptography.MACTripleDES();
        System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
        mac3des.Key = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(strKey));

        try
        {
            strDataValue = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(strValue.Split(System.Convert.ToChar("-"))[0]));

            strCalcHash = System.Text.Encoding.UTF8.GetString(mac3des.ComputeHash(System.Text.Encoding.UTF8.GetBytes(strDataValue)));
        }
        catch
        {
            throw new ArgumentException("Invalid TamperProofString");
        }
        return strDataValue;
    }
    public static string GetEncrypt(string value)
    {
        if (new HandleNull().CheckNull<string>(value).Trim().Length == 0) return value;
        return TamperProofStringEncode(value, strTamperProofKey);
    }
    public static string GetDecrypt(string value)
    {
        if (new HandleNull().CheckNull<string>(value).Trim().Length == 0) return value;
        return TamperProofStringDecode(value, strTamperProofKey);
    }

}

4

2 回答 2

1

更改此行的代码,然后尝试 w.WriteLine("");

于 2013-11-21T12:12:53.857 回答
0

这条线是错误的

w.WriteLine("<img src='Images/" + ImageName + "' alt=" + fluImage.FileName + "  />");

您需要将alt值括在引号中

于 2013-02-14T05:50:20.820 回答