I'm new to ASP.NET. Recently, I have been working on the backend (code) side of things. I'm trying to add new code to a project, but I have several options:

  • Default.aspx.cs
  • Site.master.cs
  • Site.Mobile.master.cs

EDIT: My code, as seen below, sends specific bytes to an AV receiver.

public class inputController
{
    #region Constants

    private const int ZONE2_COMMAND_DELAY = 500;
    private const string MAIN_POWER_ON = "PWON\r";
    private const string MAIN_POWER_STANDBY = "PWSTANDBY\r";
    private const string MAIN_SOURCE_FORMAT = "SI{0}\r";
    private const string SET_TUNER_FORMAT = "TFAN{0}\r";
    private const string SET_TUNER_PRESET_FORMAT = "ZMFAVORITE{0} MEMORY\r";
    private const string SELECT_TUNER_PRESET_FORMAT = "ZMFAVORITE{0}\r";
    private const string ZONE2_POWER_ON = "Z2ON\r";
    private const string ZONE2_POWER_OFF = "Z2OFF\r";
    private const string ZONE2_SOURCE_FORMAT = "Z2{0}\r";
    private const string MUTE_ON = "MUON\r";
    private const string MUTE_OFF = "MUOFF\r";

    private const string SOURCE_CABLE_SATELLITE = "SAT/CBL";
    private const string SOURCE_DVD = "DVD";
    private const string SOURCE_BLU_RAY = "BD";
    private const string SOURCE_GAME = "GAME";
    private const string SOURCE_TUNER = "TUNER";
    private string ip = "192.168.0.31";
    private int port = 23;

    #endregion

    private byte[] GetCommandBytes(string command)
    {
        return ASCIIEncoding.ASCII.GetBytes(command);
    }

    public virtual void Mute()
    {
        try
        {
            System.Diagnostics.Trace.WriteLine("Muting Denon1713.");
            using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Udp))
            {
                socket.Connect(ip, port);
                socket.Send(GetCommandBytes(MUTE_ON));
            }
            System.Diagnostics.Trace.WriteLine("Muting complete.");
        }
        catch { }
    }
    public virtual void unMute()
    {
        try
        {
            System.Diagnostics.Trace.WriteLine("Un-muting Denon1713.");
            using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Udp))
            {
                socket.Connect(ip, port);
                socket.Send(GetCommandBytes(MUTE_OFF));
            }
            System.Diagnostics.Trace.WriteLine("Un-muting complete.");
        }
        catch { }
    }
    public virtual void pwrOff()
    {
        try
        {
            Console.WriteLine("Denon1713 going on standby.");
            using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Udp))
            {
                socket.Connect(ip, port);
                socket.Send(GetCommandBytes(MAIN_POWER_STANDBY));
            }
            Console.WriteLine("Standby complete.");

        }
        catch { }
    }
}

I tried placing my new code into Default.aspx.cs and got this error:

Compiler Error Message: CS1061: 'default_aspx' does not contain a definition for 'inputController' and no extension method 'inputController' accepting a first argument of type 'default_aspx' could be found (are you missing a using directive or an assembly reference?)

Am I not calling it correctly in my webpage, or do I need to place my code into the right C# file?

Related posts

Recent Viewed