如何让 link 包含 mailto: 在 aspx 文件中?

How can I get link to include mailto: in aspx file?

 <tr>
                    <td style="border-bottom: 1px #c7c6c6 solid;">
                      <strong>
                      <asp:Label ID="Label6" runat="server" Text="Email:"></asp:Label>
                    </strong>                        </td>
                    <td style="border-bottom: 1px #c7c6c6 solid;">
                        <asp:HyperLink ID="EmailLink" runat="server"> <asp:Label ID="lblEmail" runat="server"></asp:Label></asp:HyperLink>





                    </td>
                  </tr>

隐藏代码:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.DirectoryServices;
using System.Data.SqlClient;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using System.Configuration; //added


public partial class ADdata : System.Web.UI.Page
{
  SqlConnection Conn;
  DirectoryEntry dirEntry;

  protected void Page_Load(object sender, EventArgs e)
  {
    lblStatus.Text = "";
    string connOra =
      ConfigurationManager.ConnectionStrings["UNHBannerPRODConnString"].ConnectionString;
    //Conn = new SqlConnection(matrixDBConnectString);

    //string ADUser = ConfigurationManager.AppSettings["ADUser"];
    //string ADPassword = ConfigurationManager.AppSettings["ADPassword"];
    //dirEntry = new DirectoryEntry(ADPath, ADUser, ADPassword, AuthenticationTypes.Secure);

    string ADPath = ConfigurationManager.AppSettings["ADPath"];


    dirEntry = new DirectoryEntry(ADPath);
    FillFixed_DeptPhoneNo();

    if (!Page.IsPostBack)
    {
        //-- fill up important phone numbers
        //FillFixed_DeptPhoneNo();

        string strSQL = "Select distinct(deptname) from UNH_ADDepartments order by deptname";
        OracleConnection con = new OracleConnection(connOra);
        OracleCommand cmd = new OracleCommand(strSQL, con);
        cmd.Connection.Open();
        OracleDataReader drfilldd = cmd.ExecuteReader();

      //SqlCommand cmdfilldd = new SqlCommand("Select distinct(deptname) from UNH_ADDepartments order by deptname", Conn);
      //Conn.Open();
      //SqlDataReader drfilldd = cmdfilldd.ExecuteReader();
      Dept.DataSource = drfilldd;
      Dept.DataTextField = "deptname";
      Dept.DataValueField = "deptname";
      Dept.DataBind();
      Dept.Items.Insert(0, new ListItem("-- Select Department -- ", "-1"));

      drfilldd.Dispose();
      cmd.Dispose();
      con.Close();
      con.Dispose();
        //Conn.Close();
    }
  }

  public void FillFixed_DeptPhoneNo()
  {
      //Add important phone numbers into panel pPhoneNo

  }


  public void FillGrid(string filter)
  {
    DirectorySearcher search = new DirectorySearcher(dirEntry);
    search.Filter = filter;
    search.PropertiesToLoad.Add("name");
    search.PropertiesToLoad.Add("mail");
    search.PropertiesToLoad.Add("department");
    search.PropertiesToLoad.Add("title");
    SearchResultCollection searchResultCollection = search.FindAll(); //Here FindAll()!

    DataTable dataTableResults = new DataTable();
    dataTableResults.Columns.Add("NAME");
    dataTableResults.Columns.Add("Mail");
    dataTableResults.Columns.Add("DEPARTMENT");
    dataTableResults.Columns.Add("TITLE");

    foreach (SearchResult sr in searchResultCollection)
    {
      DataRow dataRow = dataTableResults.NewRow();
      DirectoryEntry de = sr.GetDirectoryEntry();
      dataRow["name"] = de.Properties["Name"].Value;
      dataRow["mail"] = de.Properties["mail"].Value;
      dataRow["department"] = de.Properties["department"].Value;
      dataRow["title"] = de.Properties["title"].Value;
      string d = dataRow["Department"].ToString();
      if (d == "&nbsp;" || d == "")
      {
        dataRow["Department"] = null;
      }
      dataTableResults.Rows.Add(dataRow);
      de.Close();
    }

    if (dataTableResults.Rows.Count > 1)
    {
      lblFullName.Text = "";
      lblDepartment.Text = "";
      lblTitle.Text = "";
      lblExtension.Text = "";
      lblPhone.Text = "";
      lblOffice.Text = "";
      lbluserPrincipalName.Text = "";
      lblEmail.Text = "";
      EmailLink.NavigateUrl = "";
      lblFax.Text = "";



      //Select only rows with non empty email and properly formed name.
      //Sort dataTableResults by Department, Name before binding to GridView2.
      DataView dataView = new DataView(dataTableResults);
      dataView.RowFilter = @"Mail LIKE '%newhaven.edu' 
        AND Mail NOT LIKE '%0@newhaven.edu' 
        AND Mail NOT LIKE '%1@newhaven.edu' 
        AND Mail NOT LIKE '%2@newhaven.edu' 
        AND Mail NOT LIKE '%3@newhaven.edu' 
        AND Mail NOT LIKE '%4@newhaven.edu' 
        AND Mail NOT LIKE '%5@newhaven.edu' 
        AND Mail NOT LIKE '%6@newhaven.edu' 
        AND Mail NOT LIKE '%7@newhaven.edu' 
        AND Mail NOT LIKE '%8@newhaven.edu' 
        AND Mail NOT LIKE '%9@newhaven.edu' 
        AND Name NOT LIKE '%0' 
        AND Name NOT LIKE '%1' 
        AND Name NOT LIKE '%2' 
        AND Name NOT LIKE '%3' 
        AND Name NOT LIKE '%4' 
        AND Name NOT LIKE '%5' 
        AND Name NOT LIKE '%6' 
        AND Name NOT LIKE '%7' 
        AND Name NOT LIKE '%8' 
        AND Name NOT LIKE '%9'";
      dataView.Sort = "Department ASC, Name ASC";
      GridView2.DataSource = dataView; // = dataTableResults;
      GridView2.DataBind();

      Panel4.Visible = false;
      GridView2.Visible = true;
    }
    else
    {
      Panel4.Visible = true;
      GridView2.Visible = false;
    }
  } //FillGrid()

  protected void btnSearch_Click(object sender, EventArgs e)
  {
    lblStatus.Text = "";
    //btnSearch.Visible = false;
    if (txtLastName.Text.Trim() == "" && txtName.Text.Trim() == "" && Dept.SelectedIndex == 0)
    {
      lblStatus.Text = "Please enter either Firstname or Lastname or Department to search.";
      return;
    }

    try
    {
      string filter = "(&";
      if (txtLastName.Text.Trim().Length > 0)
        filter += "(sn=" + txtLastName.Text.Trim() + "*)";
      if (txtName.Text.Trim().Length > 0)
        filter += "(givenName=" + txtName.Text.Trim() + "*)";
      if (Dept.SelectedIndex > 0)
        filter += "(department=" + Dept.SelectedValue.Trim() + ")"; //department comes from ddl
      filter += ")";
      //Response.Write("filter=[" + filter + "]<br/>");

      DirectorySearcher dirSearcher = new DirectorySearcher(dirEntry);
      dirSearcher.Filter = filter;
      SearchResult searchResult = dirSearcher.FindOne();
      DirectoryEntry oneDirEntry = searchResult.GetDirectoryEntry();

      string v = oneDirEntry.Properties["userAccountControl"].Value.ToString();
      if (v == "66050")
      {
        lblStatus.Text = "This person is not enabled in the System.";
        Panel4.Visible = false;
        GridView2.Visible = false;
        return;
      }

      UnpackDirectoryEntry(oneDirEntry);

      FillGrid(filter);
    }
    catch (Exception ex)
    {
        //lblStatus.Text = (ex.Message == null ? "No Record found" : ex.Message);
        lblStatus.Text = "No Record found" ; //updated 3/24/2017 AChen. The message is not meaningful to the user
      GridView2.Visible = false;
      Panel4.Visible = false;
    }
  } //btnSearch_Click()

  public void UnpackDirectoryEntry(DirectoryEntry dirEnt)
  {
    string FirstName;
    string LastName;

    if (dirEnt.Properties["givenName"].Value == null)
    {
      FirstName = "";
    }
    else
    {
      FirstName = dirEnt.Properties["givenName"].Value.ToString();
    }

    if (dirEnt.Properties["sn"].Value == null)
    {
      LastName = "";
    }
    else
    {
      LastName = dirEnt.Properties["sn"].Value.ToString();
      lblFullName.Text = FirstName + " " + LastName;
    }

    if (dirEnt.Properties["department"].Value == null)
    {
      lblDepartment.Text = "";
    }
    else
    {
      string Department = dirEnt.Properties["department"].Value.ToString();
      lblDepartment.Text = Department;
    }

    if (dirEnt.Properties["title"].Value == null)
    {
      lblTitle.Text = "";
    }
    else
    {
      string Title = dirEnt.Properties["title"].Value.ToString();
      lblTitle.Text = Title;
    }

    if (dirEnt.Properties["ipPhone"].Value == null)
    {
      lblExtension.Text = "";
    }
    else
    {
      string Phone = dirEnt.Properties["ipPhone"].Value.ToString();
      lblExtension.Text = Phone;
    }

    if (dirEnt.Properties["physicalDeliveryOfficeName"].Value == null)
    {
      lblOffice.Text = "";
    }
    else
    {
      string Location = dirEnt.Properties["physicalDeliveryOfficeName"].Value.ToString();
      lblOffice.Text = Location;
    }

    if (dirEnt.Properties["mail"].Value == null)
    {
      lblEmail.Text = "";
      EmailLink.NavigateUrl = "";
    }
    else
    {
      string Mail = dirEnt.Properties["mail"].Value.ToString();
      lblEmail.Text = Mail;
      EmailLink.NavigateUrl = Mail;
    }

    if (dirEnt.Properties["cn"].Value == null)
    {
      lblFullName.Text = "";
    }
    else
    {
      string cn = dirEnt.Properties["cn"].Value.ToString();
      lblFullName.Text = cn;
    }

    if (dirEnt.Properties["streetAddress"].Value == null)
    {
      lbluserPrincipalName.Text = "";
    }
    else
    {
      string building = dirEnt.Properties["streetAddress"].Value.ToString();
      lbluserPrincipalName.Text = building;
    }

    if (dirEnt.Properties["telephoneNumber"].Value == null)
    {
      lblPhone.Text = "";
    }
    else
    {
      string Phone = dirEnt.Properties["telephoneNumber"].Value.ToString();
      lblPhone.Text = Phone;
    }

    if (dirEnt.Properties["facsimiletelephonenumber"].Value == null)
    {
      lblFax.Text = "";
    }
    else
    {
      string fax = dirEnt.Properties["facsimiletelephonenumber"].Value.ToString();
      lblFax.Text = fax;
    }
  }

  protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
  {
    string EmailID = Convert.ToString(GridView2.SelectedRow.Cells[2].Text);
    //DirectoryEntry dirEntry = new DirectoryEntry("LDAP://AD-NHLOCAL-03/OU=UNH Users, OU=UNH, dc= newhaven, dc= local", "Administrator", "AlphAomegA", AuthenticationTypes.Secure);
    DirectorySearcher ds = new DirectorySearcher(dirEntry);
    ds.Filter = "(mail= " + EmailID + ")";  //use email to identify a person in Active Directory!
    SearchResult emailResults = ds.FindOne();
    if (emailResults == null)
    {
      lblStatus.Text = "This entry cannot be selected because email=[" + EmailID + "].";
      Panel4.Visible = false;
      return;
    }
    DirectoryEntry employee = emailResults.GetDirectoryEntry();

    UnpackDirectoryEntry(employee);

    Panel4.Visible = true;
  } //GridView2_SelectedIndexChanged()

  protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
  {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
      e.Row.Attributes["onmouseover"] = "this.style.color='#0153a3';this.style.cursor='hand';";
      e.Row.Attributes["onmouseout"] = "this.style.color='Black';";
    }
  }

  protected void txtName_TextChanged(object sender, EventArgs e)
  {
    GridView2.Visible = false;
    Panel4.Visible = false;
    //btnSearch.Visible = true;
  }

  protected void txtLastName_TextChanged(object sender, EventArgs e)
  {
    GridView2.Visible = false;
    Panel4.Visible = false;
    //btnSearch.Visible = true;
  }

  protected void Dept_SelectedIndexChanged(object sender, EventArgs e)
  {
    GridView2.Visible = false;
    Panel4.Visible = false;
    //btnSearch.Visible = true;
  }

  protected void btnCancel_Click(object sender, EventArgs e)
  {
    txtLastName.Text = "";
    txtName.Text = "";
    Dept.SelectedValue = "-1";
    GridView2.Visible = false;
    Panel4.Visible = false;
    //btnSearch.Visible = false;
  }

  protected void GridView2_RowCreated(object sender, GridViewRowEventArgs e)
  {
    e.Row.Cells[2].Visible = false;
  }
}

我有一个正确显示的目录,但希望将电子邮件作为 mailto 进行点击:代码作为 iFrame 嵌入到页面中,因此将整个目录添加为 link例如 link 出现,但实际上是点击 https://server.com/folder/email@something.com.

查看您的代码,您需要更改此代码:

EmailLink.NavigateUrl = Mail;

成为:

EmailLink.NavigateUrl = "mailto:" + Mail;