【问题标题】:How to embed html file in dll and edit the content later?如何将 html 文件嵌入 dll 并稍后编辑内容?
【发布时间】:2012-01-29 15:01:23
【问题描述】:

我对如何使用它没有足够的想法。

目标:
1) 在 dll 中嵌入 HTML 文件

  • html 的内容是:

    美好的一天!

    您收到这封电子邮件是因为有人请求使用此电子邮件地址检索密码。 请转到以下链接以开始该过程:

    点击下方链接
    基本网址{}

    如果您没有提出此类请求,请忽略此电子邮件。

    最好, 网站管理员

2) 每次我必须发送这封电子邮件时,我都必须在嵌入的 html 中找到并用一个链接替换“BaseUrl{}”以进行验证。

3)我必须以html文件的形式发送文件,因为在进一步的开发中,我必须将图像放入文件中。

发送邮件代码:

using System.Net.Mail;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;

public static void SendEmail(MailMessage mail)
{
SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = 123;
client.Credentials = new System.Net.NetworkCredential("username@mail.com", "strongpassword");
client.EnableSsl = true;

ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);
client.Send(mail);

}  


private static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)  
{
if (sslPolicyErrors == SslPolicyErrors.None)
    return true;
else
{
    ServiceFault.WriteLog("Invalid SSL");
    return true;
}
}

或者你可以给我教程的链接,或者如果你有更好的建议,请告诉我。
谢谢!

【问题讨论】:

    标签: c# html model-view-controller dll


    【解决方案1】:

    我认为对 URI 使用字符串替换的策略很好。

    为了将其嵌入到您的 DLL 中:

    1) 创建一个包含您想要的内容的文件。
    2) 将资源文件添加到您的项目中。
    3) 添加“文件”类型资源(添加现有文件选项)并选择您的文件(这会将您的文件复制到您的项目中。
    4) 在您的代码中,使用自动生成资源访问器访问该嵌入文件的内容。

    【讨论】:

    • 这对我有用,加上添加替换方法来插入链接,问题解决了。谢谢!
    【解决方案2】:
    1. 要将文件嵌入到您的 DLL 中(我假设您使用的是 Visual Studio),请在“解决方案资源管理器”选项卡中,右键单击项目或文件夹并转到 Add->Existing Item...,然后添加您的文件到解决方案。从那里,右键单击该文件,然后单击“属性”。从那里,为“构建操作”属性选择“嵌入式资源” 从那里,您可以将文件作为字符串读取。

    2. 我会将“BaseUrl{}”更改为{0},如果您将文件作为字符串读取,请使用此代码进行替换:

      string email = string.Format(emailText, baseUrl);
      

      从那里您可以添加email 字符串作为您的消息,一切都很好!

    3. 看起来应该可以了!

    【讨论】:

    • 这将使用分发复制文件(假设设置了正确的“编译操作”但不会将其捆绑在 dll 中。为此,您必须将其专门添加为资源
    猜你喜欢
    • 2019-10-15
    • 1970-01-01
    • 1970-01-01
    • 2011-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-30
    • 1970-01-01
    相关资源
    最近更新 更多