Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

In the _Layouts folder, I have added my own subfolder and placed a few aspx files with their codebehind files. However, I'm not sure what to do with the module. The module contains variables that the other files need to reference. In a normal asp.net website, I would use the app_code folder. However, this throws an error if I put it into _Layouts\myfolder like that.

I even tried converting the module into a shared public class, but that didn't work either. Alls I want is to share variables and functions between the files in my directory.

So I am asking, where do I put my module so it can be used?

share|improve this question
add comment

2 Answers

Pages deployed to _layouts are called Application Pages.

An assembly is created when you build the project and then you need to deploy the assembly in GAC. If you are using VS.NET 2010, it takes care of packaging and deployment for you. VS.NET provides "Application Page" item when you choose to add new item to the project. Check out: http://msdn.microsoft.com/en-us/library/ee231581.aspx

share|improve this answer
    
Thanks for the answer and the link. I actually already had that very page open in my browser! I am using VS 2010 on a workstation, however, and it won't let me do anything with sharepoint since it isn't installed on the workstation. But I just want to have a simple code file that is shared between two aspx pages - is it necessary that it be compiled and GAC'd? I know that if I go in IIS and "convert" the directory to a web-application, it works just fine. –  BGM May 5 '12 at 19:51
    
Since _layouts is shared across all SharePoint web applications, I dont recommend to modify it directly from IIS. there are many different ways to get things done but I suggest only widely accepted sharepoint development practices. –  Ashish Patel May 5 '12 at 21:43
    
I didn't mean to modify the _layouts folder, I meant to make my _layouts\myfolder into a web-application. Sorry, I should have been more clear in my comment. –  BGM May 6 '12 at 1:20
add comment
up vote 1 down vote accepted

One cannot develop against Sharepoint unless Sharepoint is running on the same machine as VS which is necessary in order to compile dlls with Sharepoint references to be GAC'd. A workaround is to turn the _layouts\myfolder into a web-application via iis. Locate the directory in iis under the sharepoint site, right-click on it, and select "convert to web-application". You can let it inherit its parent's application pool.

This works - it allows you to have a _layouts\myfolder\app_code folder in which to put class.cs files without having to compile them. You can also reference sharepoint assemblies, like microsoft.sharepoint without any additions your new application's web.config file.

Another thing you get is custom error pages, if you specify them in _layouts\myfolder\web.config. Also, you can use <customErrors mode="Off"/><compilation debug="true"/>, which is useful for debugging your page.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.