2017-05-11 15 views
0
<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> 

코드 :mailto : aspx 파일에 링크를 포함하려면 어떻게해야합니까? 뒤에

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 '%[email protected]' 
     AND Mail NOT LIKE '%[email protected]' 
     AND Mail NOT LIKE '%[email protected]' 
     AND Mail NOT LIKE '%[email protected]' 
     AND Mail NOT LIKE '%[email protected]' 
     AND Mail NOT LIKE '%[email protected]' 
     AND Mail NOT LIKE '%[email protected]' 
     AND Mail NOT LIKE '%[email protected]' 
     AND Mail NOT LIKE '%[email protected]' 
     AND Mail NOT LIKE '%[email protected]' 
     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; 
    } 
} 

나는 올바르게 표시되는 디렉토리가 있지만 흔한으로 이메일 클릭하고 싶은 : 코드가 iframe을 같은 페이지에 내장되는 자사의 추가 정도 예를 들어 링크 전체 디렉토리가 나타나지만 실제로는 https://server.com/folder/[email protected] (으)로 연결됩니다.

EmailLink.NavigateUrl = Mail; 

가 되려면 :

+0

가능한 중복 : http://stackoverflow.com/questions/7357189/how -to-set-asphyperlink-href-to-mailtoabchotmail-com-in-net-c-sharp – voam

답변

0

코드를 보면, 당신은이 코드를 변경해야 할 것

EmailLink.NavigateUrl = "mailto:" + Mail; 
+0

코드를 볼 수 있도록 질문을 업데이트했습니다. 고마워요, – Bove

+0

내 대답 업데이트했습니다 :) – Tim

+0

그 메일 값을 취할 수있는 개인적인 방법을 쓰고 싶다면 "https://server.com/folder/"가 있는지 확인하십시오. 그런 다음 Tim이 EmailLink.NavigateUrl에 할당하기 전에 Mail에서 "mailto :"를 제안하고 앞에 추가합니다. – Rod