Search code examples
c#asp.netvisual-studio-2017asp.net-webcontrol

Why am I seeing 'type or namespace 'HtmlIframe' does not exist in the namespace 'System.Web.UI.HtmlControls' (are you missing an assembly reference?)'


Just resurrected an old website that I haven't worked on in several years. Created a new ASP Website project in Visual Studio and imported all the files.

Everything works fine except for one page. It keeps giving me an error on an inline that the page contains. Other pages also use an iframe but aren't (yet) throwing errors.

The page uses a C# code behind along with a master page.

<%@ Page Title="" Language="C#" MasterPageFile="~/MASTERS/HRIS.master" AutoEventWireup="true" CodeFile="PayFile.aspx.cs" Inherits="business_Wireless_PayFile" %>

<asp:Content ID="Content1" ContentPlaceHolderID="pageTitle" runat="Server">
    Wireless Payments
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="pageJavascript" runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="pageStyle" runat="Server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="pageName" runat="Server">
    Wireless Payment File
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="pageData" runat="Server">
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="pageUpdateProgress" runat="Server">
    <table>
        <tr>
            <td colspan="2">
                <iframe name="txtFrame" runat="server" id="txtFrame" width="90%" height="300px"></iframe>
            </td>
        </tr>
        <tr>
            <td width="90%" style="margin-right: 0px; text-align: right;">
                <asp:Button ID="btnAccept" runat="server" Text="Accept" Width="100"
                    OnClick="btnAccept_Click" />&nbsp;</td>
            <td style="margin-left: 0px; text-align: left">&nbsp;<asp:Button ID="btnCancel"
                runat="server" Text="Deny" Width="100" OnClick="btnCancel_Click" /></td>
        </tr>

    </table>
<!-- OTHER CODE HERE -->
</asp:Content>

And the code behind:

using System;
using System.Data.SqlClient;
using System.Net.Mail;
using System.Text.RegularExpressions;
using System.Web.UI;

public partial class business_Wireless_PayFile : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Request["sID"] == null || Request["sID"] == string.Empty)
            {
                Response.Redirect("/default.aspx");
            }

            SqlConnection con = CompanyClass.Data.getConnection("Dev_IntranetConnectionString");
            SqlCommand cmd = new SqlCommand("", con);
            cmd.CommandText = "Select HOFile, Approved from tblWirelessPayFiles WHERE Session='" + Request["sID"] + "'";

            string ho = string.Empty;
            bool approved = false;
            con.Open();
            SqlDataReader dr;
            dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                ho = dr["HOFile"].ToString();
                approved = Convert.ToBoolean(dr["Approved"]);
                con.Close();
            }
            else
            {

                txtFrame.Attributes.Add("src", "404page.htm");
                btnAccept.Enabled = false;
                btnCancel.Enabled = false;
                con.Close();
                return;
            }

            if (!approved)
                
                txtFrame.Attributes.Add("src", Regex.Split(ho.Replace("\\", "/"), "client/")[1]);
            else
            {
                txtFrame.Attributes.Add("src", "PreApproved.htm");
                btnAccept.Enabled = false;
                btnCancel.Enabled = false;
                pnlDenyReason.Visible = false;
            }
        }
    }

    protected void btnAccept_Click(object sender, EventArgs e)
    {
        
        string mailFrom = "webforms@somecompany.com";
        string mailSubj = "Payfile Problem from Head Office";
        string mailTo = "someone@somecompany.com";
        string CC = "someoneelse@somecompany.com";
        string emailText = "Payfile approved.  Download file from ";
        emailText += "<a href='http://" + Request.Url.DnsSafeHost + "/business/Wireless/getFile.aspx?sID=" + Request["sID"];

        emailText += "'>this link</a>";

        string mailBody = "<html><body>" + emailText + "</body></html>";

        MailMessage msgMail = new MailMessage(mailFrom, mailTo, mailSubj, mailBody);
        msgMail.CC.Add(CC);

        msgMail.IsBodyHtml = true;
        SmtpClient clnt = new SmtpClient();
        clnt.Host = "mail2.mcad2.local";
        clnt.Send(msgMail);

        txtFrame.Attributes["src"] = "Datasent.htm";

        SqlConnection con = MCAIntranet.Data.getConnection("ConnectionString");
        SqlCommand cmd = new SqlCommand("", con);
        cmd.CommandText = "Update tblWirelessPayFiles set Approved='true' WHERE Session='" + Request["sID"] + "'";
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
    }

    protected void btnCancel_Click(object sender, EventArgs e)
    {
        pnlDenyReason.Visible = true;
        btnAccept.Enabled = false;
        btnCancel.Enabled = false;
    }


    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        //take the problem details and email them to Dean & Stanley
        //redirect frame page to post "Problem Details have been sent" copied from SentData

        string mailFrom = "webforms@somecompany.com";
        string mailSubj = "Payfile Problem from Head Office";
        string mailTo = "someone@somecompany.com";
        string CC = "someoneelse@somecompany.com";
        string emailText = "Payfile not approved.  Problem details: <br /><br /> ";
        emailText += "<div style='font-weight:bold;font-size:15px; padding 10px;'>";
        emailText += txtDenyReason.Text.Replace("\r\n", "<br />");//format email as HTML
        emailText += "</div>";

        string mailBody = "<html><body>" + emailText + "</body></html>";

        MailMessage msgMail = new MailMessage(mailFrom, mailTo, mailSubj, mailBody);
        msgMail.CC.Add(CC);

        msgMail.IsBodyHtml = true;
        SmtpClient clnt = new SmtpClient();
        clnt.Host = "mail.somecompany.net";
        clnt.Send(msgMail);

        txtFrame.Attributes["src"] = "ProblemSent.htm";
        txtDenyReason.Text = "Problem information has been delivered.";
        btnSubmit.Enabled = false;

    }

   }

I have attempted to recreate the entire page, pasting in the code as necessary and excluding the original. I am getting a secondary error 'ASP.business_wireless_payfile_aspx' does not implement interface member 'System.Web.IHttpHandler.IsReusable'`` in the temporary file c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\21c404eb\43bc3cfb\App_Web_df3ljkuy.0.cs```

I originally attempted to import this project as a web application, then switched back to a website. Could this be part of the issue?


Solution

  • Because your interface is IHttpHandler, you need to add the following code after processing the request when implementing the IsReusable method:

    protected bool IsReusable
          {
             get { return true; }
          }
    

    For details, please refer https://learn.microsoft.com/en-us/dotnet/api/system.web.ihttphandler.isreusable?redirectedfrom=MSDN&view=netframework-4.8.1#System_Web_IHttpHandler_IsReusable