1

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?

Geoff
  • 353
  • 3
  • 19
  • BTW, you should consider changing from _Website_ (i.e. `CodeFile="PayFile.aspx.cs"`) to _Web Application_ (`CodeBehind="PayFile.aspx.cs`). Website projects quickly fall-apart due to lacking a `.csproj` file and AOT compilation. – Dai Feb 07 '23 at 22:14
  • 1
    [missing HtmlIframe from System.Web.UI.HtmlControls](https://stackoverflow.com/questions/22763732/missing-htmliframe-from-system-web-ui-htmlcontrols) might be related – stuartd Feb 07 '23 at 22:48
  • If this is a web site then you shouldn't have any designer files, but only aspx and .cs files. So, delete the designer class file if you see or have one – Albert D. Kallal Feb 08 '23 at 00:30
  • @Dai This is an old website. I tried earlier converting to Web Application and ran into the same issues. Keeping it as is for easy of work and it's only deployment is on local webserver – Geoff Feb 08 '23 at 13:54
  • @stuartd I've already looked at this. I am simply using – Geoff Feb 08 '23 at 14:00
  • @AlbertD.Kallal There is no designer file that I can find. – Geoff Feb 08 '23 at 14:00

1 Answers1

1

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

wenbingeng-MSFT
  • 1,546
  • 1
  • 1
  • 8
  • Where has the IHttpHandler interface come from? I am inheriting from Page, as I have in multiple other pages. Either way adding the IsReusable worked, I just don't understand why it was needed. – Geoff Feb 08 '23 at 14:06
  • @Geoff Page inherits System.Web.UI.TemplateControl, System.Web.IHttpHandler. For details, please refer to https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.page?view=netframework-4.8.1 – wenbingeng-MSFT Feb 09 '23 at 01:40
  • I see that, but why did I need to add the IsReusable? Is that not already encoded? I've never had to add it to other pages which have similar code and design. – Geoff Feb 10 '23 at 14:06
  • @Geoff Explanation that comes with the framework: If it is set to true, the example can be used multiple times, but the specific meaning is actually quite abstract. General explanation on the Internet: Set to true, high performance, but thread safety must be guaranteed (that is, static variables cannot be used, or static variables can be locked) In fact, using the above two sets of explanations, we can roughly deduce the principle of its rules. – wenbingeng-MSFT Feb 13 '23 at 01:46
  • Web requests must be a multi-threaded and highly concurrent environment, and the difference in the IsReusable attribute directly indicates how .Net should handle the request after receiving it. I boldly speculate about the internal implementation code of .Net. – wenbingeng-MSFT Feb 13 '23 at 01:47
  • The function of the IsReusable attribute should be used to determine whether it is used for static caching. If static caching is used, it can greatly save the time cost of object creation, thereby improving performance. At the same time, it is used for objects at the static variable level, and the problem of threads is naturally highlighted. – wenbingeng-MSFT Feb 13 '23 at 01:47