如何从.resx文件获取凭据 [英] how to get the credentials from .resx file

查看:79
本文介绍了如何从.resx文件获取凭据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在开发Web应用程序,在Web应用程序中,我们正在使用RDLC报告.
要通过报告发送电子邮件,我为用户提供了静态凭据
除了提供.cs页面外,我还需要提供.resx文件

我应如何在.resx文件中提供用户凭据并将其转到.aspx.cs页

请给我它的示例代码:

以下是我的代码:

hi all,

I am working on web application,In web application we are using RDLC reports.
To send an email through report i am giving user credentials static
Instead of giving in .cs page i need to give in .resx file

How should i give the user credentials in .resx file and get them to the .aspx.cs page

please give me the sample code of it :

below is my code:

private void SendMailinxls(ReportViewer reportViewer)
{
    Warning[] warnings;
    string[] streamids;
    string mimeType;
    string encoding;
    string extension;

    byte[] bytes = reportViewer.LocalReport.Render
("Excel", null, out mimeType, out encoding, out extension, out
streamids, out warnings);

    MemoryStream memoryStream = new MemoryStream(bytes);
    memoryStream.Seek(0, SeekOrigin.Begin);

    MailMessage message = new MailMessage();
    Attachment attachment = new Attachment(memoryStream, "Report1.xls");
    message.Attachments.Add(attachment);

    message.From = new MailAddress("aaa@gmail.com");
    message.To.Add("bbb@yahoo.com");

    message.CC.Add("bbb@yahoo.com");

    message.Subject = "Caste Report";
    message.IsBodyHtml = true;

    message.Body = "Please find Attached Report herewith.";


    SmtpClient smtp = new SmtpClient();
    smtp.EnableSsl = true;
    NetworkCredential smtpCredential = new NetworkCredential("aaa@gmail.com", "12345");
    smtp.UseDefaultCredentials = true;
    smtp.Credentials = smtpCredential;
    smtp.Port = 587;
    smtp.EnableSsl = true;
    //SmtpClient client = new SmtpClient("smtp@gmail.com", 587);
    //client.Credentials = smtpCredential;

    //client.Send(email);
    smtp.Send(message);

    memoryStream.Close();
    memoryStream.Dispose();
}


web.config文件:


web.config file:

<system.net>
    <mailSettings>
      <smtp from="aaa@gmail.com">
        <network host="smtp.gmail.com" port="587" userName="aaa@gmail.com" password="12345" enableSsl="true" />
      </smtp>
    </mailSettings>
</system.net>


我应该以加密格式在resx文件中提供凭据,而不是在web.config和codebehind中给出凭据.


I should give the credentials in the resx file in encrypted format instead of giving in web.config and codebehind

推荐答案

您可以使用GetLocalResourceObject或GetGlobalResourceObject来读取资源文件.
以下链接可能会有所帮助:-
https://msdn.microsoft.com/en-us/library/ms227982%28v = vs.140%29.aspx [ ^ ]
You can use GetLocalResourceObject or GetGlobalResourceObject to read the data from the resource files.
Following link might help:-
https://msdn.microsoft.com/en-us/library/ms227982%28v=vs.140%29.aspx[^]


这篇关于如何从.resx文件获取凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆