tags:

views:

711

answers:

4

Working on our restricted system means I cant drop class librariess into the app_bin/bin/App_Code basically any normal folder, so I'm currently linking to my class library as follows...

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="~/cs/codebehind.cs" Inherits="codebehind"  %>
<%@ Assembly Src="~/cs/mycodelibrary.cs" %>

The problem I'm trying to solve is how would I reference the class library as a file in the codebehind so I don't need to have another thing on the page, and VS stops telling me the things in the assembly don't exist.

i.e

using "~/cs/regionalPages.cs"


Quick addition, adding the mycodelibrary.cs as above does work. I'm just trying to find a better way.

And i should reaffirm that I have no access to normal .net folders, if I did I wouldn't be asking this seemingly dumb question.

A: 

First of all, a .cs file is not an assembly. It must be compiled into a DLL first before it can be considered an assembly.

In order to reference the code in the assembly imported at the page-level, I believe you will have to put your server-side code inline with the markup (as opposed to having a separate aspx.cs file).

Best regards...

Josh Stodola
I know its not an assembly, it just works, and DLL's wont load from a normal folder (without changing the server settings)
Chris M
+1  A: 

So. You miss real servers.

Why don't you use the App_Code folder and let ASP.NET handle the compilation and reference paths for you? That's what it's for.

Edit: Hm. You're saying you don't have access to App_Code, but you have a folder called cs where you can drop code files instead? That's a very strange arrangement. What would whoever restricted your access in the first place think about that?

Another thing i don't get is how your mycodelibrary.cs will be compiled at all. ASP.NET handles compilation inside the App_Code folder, but not elsewhere (or am I wrong?).

Another edit: OK, I've got it now, and have tried it out. The @Assembly directive in the .aspx page ensures the code file is compiled, and a reference to it made available to the page. Then the reference is also available in the codebehind (even with intellisense), since it's the same (partial) class.

Now, is you question how you can accomplish the same thing without the @Assembly directive in the .aspx file (but rather something in the codebehind)? I can tell you no form of using will do the trick, at least. Honestly, I can't see any way to accomplish that, sorry.

Cerebrus mentions configuring the runtime with codebase or probing in Web.config, but that only works with compiled assemblies.

Tor Haugen
Really? read line 1
Chris M
the CS folder is just a normal folder I choose to create to store all the cs files (rather then having them scattered around the sites). + yes they work. I try not to worry too much about why they work and thank god something does.
Chris M
Bingo, maybe I'll just give in, build it all on google apps in python as an api and access it from a page behind... probably faster too.When the support contract runs out with the Indian Dev company I'll be dancing. Thanks
Chris M
A: 

DLL's can be loaded from what you might describe as a "normal" folder. However you need to instruct ASP.NET to load assemblies from the specified folder, for instance, using the codebase or probing elements in the configuration file.

Take a look at this MSDN article which explains the procedure and syntax.

Cerebrus
I'll change the page a little. I know you can change the folder it looks at, I dont have access to the core folder so I definatly dont have access to change ASP's settings.
Chris M
+1  A: 

Hi,

Here you go:

  1. First Create a new User Control : UC_TestingPOC.ascx,
  2. Create a new Class Library : UserControlsCodeBehind,
  3. Under the Class Libray, add the code behind class for the user control created earlier: UC_TestingPOC.ascx.cs

On the top of your user control, add the following lines:

<%@ Assembly Name ="UserControlsCodeBehind, Version=1.0.0.0, Culture=neutral, PublicKeyToken=00000000000000" %>

<%@ Control Language="C#" AutoEventWireup="true" Inherits="UserControlsCodeBehind.UC_TestingPOC" %>

-- Hope this will help you.

Basem Alabbasi