asp.net 为什么在命名空间“System.Web.UI.HtmlControls”中不存在类型或命名空间“HtmlIframe”(是否缺少程序集引用?)

0qx6xfy6  于 2023-02-10  发布在  .NET
关注(0)|答案(1)|浏览(215)

刚刚恢复了一个几年没做的旧网站。在Visual Studio中创建了一个新的ASP网站项目,并导入了所有文件。
除了一个页面之外,其他页面都运行良好。它总是在页面包含的内联上给我一个错误。其他页面也使用iframe,但还没有抛出错误。
该页使用了C#代码沿着母版页。

<%@ 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>

以及背后的代码:

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;

    }

   }

我已尝试重新创建整个页,根据需要粘贴代码并排除原始代码。出现次要错误'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 '''
我最初尝试将此项目作为Web应用程序导入,然后切换回网站。这会是问题的一部分吗?

8tntrjer

8tntrjer1#

由于您的接口是IHttpHandler,因此在实现IsReusable方法时,需要在处理请求之后添加以下代码:

protected bool IsReusable
      {
         get { return true; }
      }

详情请浏览https://learn.microsoft.com/en-us/dotnet/api/system.web.ihttphandler.isreusable?redirectedfrom=MSDN&view=netframework-4.8.1#System_Web_IHttpHandler_IsReusable

相关问题