ASP .net ignore tags based on version
I am dep开发者_Go百科loying my asp.net in 2 different servers (2.0 and 3.5 .net version). some tags are not supported in .net 2.0. How can i check the .net version and ignore the html tags?
for example, AJAX .. i want to disable <asp:ScriptManager>
in .net 2.0
Under the project properties, you can target the .Net 2.0 framework. That will remove the .Net 3.5 only references.
The tags in an .aspx file is statically compiled to a series of object instantiations. Is is impossible to use some tags when the corresponding type is not present.
If you need to target both ASP.NET 2.0 and 3.5, you need to use the specific features of ASP.NET 3.5 in your code-behind, and only after testing the current version. The code using the 3.5 features must be in specific methods that are never called if you are under 2.0. The JIT compiler works at the method granularity, so you could have unknown types in a never-called-method. But the following cannot work:
void f() {
if (IsRunningUnderAspNet35) {
AspNet35Class xxx = new AspNet35Class();
}
}
But the following works:
void f() {
ICommonInterface i;
if (IsRunningUnderAspNet35) {
i = FactoryUsingAspNet35Class();
} else {
i = FactoryUsingAspNet20Class();
}
// use i
}
If you're using DLLs that reference AspNet 3.5, you need to load them dynamically, not through static project references.
Note: you're much better off trying to convince the server admin to install ASP.NET 3.5.
精彩评论