How to use an additional C # source file on a page in a website project?

Edit: {I think I have added a lot (too much) of information (reading) here. The important parts of what I want are:

  • I am using a website (.csproj file)
  • I need some source code files for my aspx to run
  • As far as I understand, I need to either use a precompiled DLL or tell .NET to compile additional files on the fly when an ASPX file is requested.
  • I am not sure how to make any situation work.
  • If you provide reference information on a DLL, please tell me which instruction to use and put in which file (ASPX directive, web.config, etc. cannot use .csproj).
  • If you provide help on another parameter, please provide the operator that will be used to include the MULTIPLE source files, and where to put the instruction (ASPX directive, web.config, etc. - cannot use .csproj) - I already use @Page CodeBehind / CodeFile, I need more than one source file

}

I am trying to include additional C # source files in my ASPX file, it does not work.

I have Default.aspx (with @Page CodeFile = "Default.aspx.cs") and would like to link to other files (like LinkList.cs, SQLiteDB.cs, SQLServerDB.cs, JSON.cs).

I think it should be something like this (in the Default.aspx file):

// <% @Reference Page = "secondfile.cs"%>

ASP/.NET, #, PHP, JS, - .. , ; , .

- ( ; ), ( VS!) . VS, , , VS, ... , , VS ( ), - , .

, :

  • #, , CodeFile, ; , .
  • , @Page CodeFile (NOT CodeBehind); , #.

, :

  • HTML script (); , " ", " ", #.
  • <% @Reference Page = "secondfile.cs" % > (: "" src " , ."; , 'src' from, , 'src' Reference...)
  • " " , , ... /www/dev/ *, #
  • <% @Assembly Name= "assemblyname" % > <% @Assembly src= "pathname" % >

, , , : "CS0246: " SQLServerDB " ( ? )"

    <%@ Assembly Src="SQLServerDB.cs" %>
    <%@ Assembly Src="DataSource.cs" %>
  • "using myNS.SQLServerDB"

, ... , . asp.

/. , - ( -), ASP Server CodeFile? . "use" , , .

+4
4

, . , , . -, , .

  • @Alexei , App_Code. , ASP.NET, , - , - , , , . , () , , App_Code -, , , , , , .NET.

  • - @Page .ASPX. : "App_Code" , .NET "App_Code" ; , , , , .

<% @Assembly src= "App_Code/Utilities/SQLServerDB.cs" % >

<% @Assembly src= "App_Code/Utilities/Functions.cs" % >

<% @Assembly src= "App_Code/Utilities/Database.cs" % >

<% @Assembly src= "App_Code/Utilities/LinkedList.cs" % >

<% @Assembly src= "App_Code/DataObjects.cs" % >

: , , . , . . , , , , . "using" ; , .

, !

+4

(, LinkList.cs, SQLiteDB.cs, SQLServerDB.cs, JSON.cs), Default.aspx.cs.

+1

. , Visual Studio, -, -. . , .

.cs . .dll . .cs , , .

1: .cs, Visual Studios. " > " .cs. dropp "" " "

2: , , using Default.aspx.cs. :

using System.Web.UI.WebControls; /*This should already be there**/
using [NameSpace].LinkList;
using SQLLiteDB;

3: Default.aspx.cs . :

LinkList myList = new LinkList();

, -. , LinkList - , HTML , Very.

+1

, App_code.

In a website project, you can store the source code in the App_Code folder and it will be automatically compiled at runtime. The resulting assembly is available for any other code in the web application. Therefore, the App_Code folder works the same as the Bin folder, except that you can store the source code in it instead of the compiled code.

Put the common classes in the App_Code folder and they should be compiled / visible to all pages.

+1
source

Source: https://habr.com/ru/post/1543924/


All Articles