Is dynamic compilation in a 'ASP.NET Web Application' possible? - asp.net

Can I somehow utilize the App_code folder in a web application project to compile code on the fly? It'd be great for plugins. Recently Rob Conery demonstrated its use in his talk at MIX 09 in a ASP.NET MVC app. I tried to do the same in a web app but I can't access the classes under App_Code from anywhere else. But if Rob was able to do it in an MVC app, it should be doable in a web application too. After all ASP.NET MVC IS a ASP.NET Web Application under the covers.

If you add a code file to the App_Code folder, it should be compiled and available from a code-behind file for a control, or another code file in the App_Code file.
I don't think you'll be able to access it directly from a compiled assembly, since the compiler won't be able to find that reference at compile time.
You'll also need to be aware that App_Code is compiled into a different assembly than your code-behind code, so you can't access internal code across the different assemblies.

Related

Reference aspx pages from different web project

I have an ASP .NET web form solution with multiple web projects. There is one core web project and each of the other web project work as pluggable modules.
I have written a post build event to copy aspx/ascx files and *.dll of child web projects to the core web project directory.
The issue is - I am not able to call child project aspx pages from the core project. I get "Could not load type" error.
Is it possible to use aspx pages in different project if i refer that webproject dll and copy the aspx files to the main application? What am i doing wrong here. I would greatly appreciate any pointer in the right direction. Thank you.
Sanjay
I found answer to this. The key is to define you assemblies in the web.config file and then define a probing path. Following is the link with details-
http://weblogs.asp.net/chrismoseley/archive/2008/10/28/shared-assemblies-without-the-gac.aspx

Why is my ASP.NET site building to a DLL? And what does this mean?

I have built ASP.NET web sites before and usually I start my solution as an ASP.NET Web Site but this time I started it as a Class Library. I then added a web site to the solution. Now when I build my solution I get WebSiteName.dll in bin\.
What does this mean? Is this some compiled instance of my site? Can I use it on my ASP.NET host (arvixe.com)?
Your application is functioning as a web application project now instead of a web site project. Web application projects precompile all of your source code into a DLL, whereas web site projects compile your application on the fly using the code files.
What does this mean? Is this some compiled instance of my site? Can I use it on my ASP.NET host (arvixe.com)?
Yes.
Depending on how it's compiled, you may need more than just that DLL though.
Basically, the web server loads your DLL and the DLL contains your website's code. Depending on how it's compiled, many times you'll need both the DLL and the .aspx pages(and of course images and javascript). But yes, all ASP.Net sites generate a DLL.

what is the difference between creating a web application and a web site?

Why does an assembly get created when I am building a web site? I mean a web site and not a web application.
The difference is quite big. A web site is not compiled. Code is placed in the App_Code folder and dynamically compiled by ASP.NET at runtime. A web application is precompiled meaning that you can place code wherever you want and it will produce an assembly at compile-time. You also get a project file .csproj associated with it.
Here's an overview on MSDN.

Strategies for Hosting 2 .NET Languages in Same Web App

I have 2 web sites (in Visual Studio - separate solutions) - one in VB.NET, one in C#. Ideally, I'd like to make them both web application projects, compile each codebase into to a DLL, drop both DLLs in the bin and drop both sets of .aspx pages under web root folder. So some aspx files would have Language="C#" and some Language="VB.NET", and in the bin you'd have /bin/MyVB6.dll, /bin/MyCSharp.dll. The .aspx pages could be broken up into separate sub-directories. Is this even possible? - Or would they need to be separate virtual directories/web apps in IIS?
Thanks
I see no reason why you can't do that (you can even have one assembly with the help of MSBUild and ILMerge). In a web application the language declaration does not matter and the classes are loaded from the pre-compiled dlls. In a web project each page is compiled at runtime in its own assembly. However you may need to hack your Visual Studio's project files to build the source code in case of web application. To stay safe I suggest you move your code to user controls in separate class library projects.

Deploy asp.net application without compiling DLL

When I publish any type of asp.net application, my code is precompiled into various assemblies. I would like to avoid this so that I can upload an aspx page and its corresponding codebehind file. I understand the benefits of doing it either way, but what is desired here is the least risky way to publish changes.
How does one properly deploy an asp.net project without compiling assemblies?
Is the process different for each model (web app, MVC..)
Sounds like you have a Web Application Project, and what you want is a Website Project. With website projects, you can modify the aspx and codebehind files and not have to worry about recompliling them, asp.net will do that for you. Web Application Projects need to be compiled for every code change.

Resources