What is the purpose of precompiledApp.config? - asp.net

If you precompile a web site and keep it updatable, the ASP.NET parser can see from the Page directive that there is no codefile or codebehind and where to find the base class (inherits attribute).
<%# page language="C#" autoeventwireup="true" inherits="_Default, Precompiled"
theme="Default" validaterequest="false" %>
If the site is precompiled and not updatable, the .compiled files in the bin folder should give the ASP.NET runtime all the necesary information on how to instantiate the page classes.
So why is the precompiledApp.config needed?
Thanks!

It's used to indicate whether or not the ASPX/ASCX pages in your site are updateable or not. You can precompile and have the code behind compiled, but leave these pages updateable so you can make minor GUI-related tweaks should you wish.

Related

Parse Error - Could Not Load Type

I've been experiencing this issue on my Web App. The line throwing the error is:
Line 1: <%# Page Language="vb" AutoEventWireup="false" Codebehind="foo.aspx.vb" Inherits="foo" %>
Things to note:
This was a working web application on .NET 2.0. I wanted to migrate it to .NET 4.0.
The codebehind file exists.
The Partial class in the Inherits attribute exists.
The .dll's are updated in the bin\ of the project and in the bin\ of wwwroot.
I have been to multiple sites and similar questions here in StackOverflow, but the solution suggested are always to check the items in the list above.
I am not sure about your Inherits attribute value in below line
<%# Page Language="vb" AutoEventWireup="false" Codebehind="foo.aspx.vb" Inherits="foo" %>
Inherit attribute contains the full namespace path. So go to your code behind file and check the namespace in which foo class exists. It may be exists in your project namespace. Like if your project name is MyProject then it should be something like this MyProject.foo
<%# Page Language="vb" AutoEventWireup="false" Codebehind="foo.aspx.vb" Inherits="MyProject.foo" %>
Go to IIS:
Change your web application pool framerwork from version .NET 2.0 to 4.0

Ajax Control Toolkit fails to load

I am having trouble getting my AJAX control tool kit working in asp.net. The website runs fine when I run it using the localhost/website.aspx address however when I attempt to access the website via the net I get the error below. Any Suggestions?
Parser Error Message: Could not load file or assembly
'AjaxControlToolkit' or one of its dependencies. The system cannot
find the file specified.
Line 1: <%# Page Language="VB" AutoEventWireup="false"
CodeFile="Submit_Employee_Info.aspx.vb" Inherits="_Default"
MaintainScrollPositionOnPostback="true" %>
Line 3: <%# Register Assembly="AjaxControlToolkit"
Namespace="AjaxControlToolkit" TagPrefix="asp" %>
Source File: /RequestForm/Submit_Employee_Info.aspx Line: 3
Sorry not much reputations so posting as answer instead of comments. Do you have ajax toolkit dll referenced in your project. To confirm, check your bin/debug director.
In your local solution, expand the references folder in the web application, and find the AjaxControlToolkit.dll.
Right click, Properties, and check the path to where the DLL is referenced
If it's referenced to a folder outside of your project, you will need to include this in the project.
You have a couple of choices...
Copy DLL into a 3rdPartyLibs folder in the solution, and change the reference to point here
Use Nuget to download the file into the solution, the only issue here is that the version may be incorrect, so option 1 here might be best in your scenario.

Why "CodeBehind" on Web App or WCF App?

I'd like clarification of what seems to be a contradiction in MSDN documentation.
MSDN makes very clear the distinction between a "web site" and a "web application." For example, it says you should use an "application" instead of a "site" if...
You want to avoid putting source code on a production server.
Ok, sounds good, but when you create an ASP.NET MVC "app" or a WCF service "app", the first thing you get is a description file with a CodeBehind that specifies what source code to reference. Examples:
For ASP.NET MVC
<%# Application Codebehind="Global.asax.cs" Language="C#" Inherits="Sample.MvcApplication" %>
For a WCF service app
<%# ServiceHost CodeBehind="MyService.svc.cs" Language="C#" Service="Sample.MyService" %>
In both these "app" examples, the "CodeBehind" assumes you have placed source code on your production server. In short, what you receive from a Visual Studio "App" or "project" template basically contradicts the claim made by MSDN documentation.
What makes this more strange is that, at least in some caes, this doesn't need to be this way. For example, another valid way for the WCF service description file to be generated is like this:
<%# ServiceHost Language="C#" Debug="true" Service="Sample.AccountService" %>
<%# Assembly Name="Sample.AccountService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" %>
With the "Assembly" directive, it is not necessary to specify a CodeBehind target. If a purpose of a WCF app (in contrast with a WCF site, which is also a Visual Studio option) is to have no source code on a production server, why then is the service definition file not generated as shown in the last sample above?
What is the rationale that allows this apparent contradiction?
You want to avoid putting source code on a production server.
This is referring to the ability use non-compiled code. With a website, you have the ability to copy your aspx.cs or aspx.vb files (in clear text) along the aspx files and have them run. You can also modify them in clear text because they are not compiled.
A web application differs because must be compiled, the source code exists in DLLs.

Deploying SharePoint layout ASP .NET assembly into GAC

I'm currently rewriting a legacy SharePoint application and I need to figure out how to deploy it.
The application itself is SharePoint solution with several features, including webparts and simple web pages with some code.
There is a webpage that is designed to be deployed in layouts subfolder.
In production environment, there is no codebehind in layouts subdirectory, just the .aspx file.
I understand that corresponding codebehind assembly is loaded from GAC. Indeed, it is there.
However the page code doesn't contain <%# Assembly %> directive that would ask it look in GAC, nor does it specify fully-qualified name:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="BadWolf._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- -->
</html>
So how does this page locate its code assembly in the production environment? I need to deploy the same code to a different server but if I don't specify <%# Assembly %> SharePoint gives me Unknown Error, which is represented in logs as follows:
Exception Type: System.Web.HttpException
Exception Message: Could not load type 'BadWolf._Default'.
What did I miss? Is there any special config, any special setting, whatever?
You need to use Inherits= with the fully qualified assembly name...
Inherits="MyAssembly.MyNamespace.MyClass, MyAssembly, version=1.0.0.0, culture=neutral, publickeytoken=123456789"
Turned out the assembly was in SharePoint bin folder, that's why it was loaded without specifying the fully qualified name. However removing it from GAC yielded another issue:
Request for the permission of type 'Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' failed
This is funny because removing the assembly from either GAC or bin folder makes it unusable (or else requiring additional configuration which I seek not), and I'm not sure which one is actually being loaded.
I think I'll stick with keeping assembly in GAC (to have full trust) and specifying fully qualified name.

Asp.net .aspx and MVC Co-existing project, the Codebehind/Codefile still existing inside .aspx files after project published

We have Asp.net .aspx and MVC Co-existing project, Codebehind/Codefile are still existing inside .aspx files after project published, it needes a lot of effort to get rid of these after deployment:
we have to manually change every .aspx file
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPages/xxx.master"
AutoEventWireup="true" Inherits="xxx.Login" Codebehind="Default.aspx.cs" %>
To
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPages/xxx.master"
AutoEventWireup="true" Inherits="xxx.Login" %>
it is ton of work to do that
anyone can help?
Thanks
You don't need to remove the Codebehind attribute from your ASPX files.
You just deploy them without .CS files.
The classes specified in the Codebehind are compiled in to the assembly and are available after the assembly gets deployed (which you do always).

Resources