这个问题之所以存在,是因为它确实存在 具有历史意义,但事实并非如此 被认为是一个很好的主题问题 因为是本网站,所以请不要使用 作为证据,你可以问类似的问题 这里的问题。 更多信息:https://stackoverflow.com/faq


总有一些功能在边缘场景中很有用,但正是因为这个原因,大多数人都不知道它们。我要求的是课本上通常没有教过的特性。

你知道的是什么?


当前回答

代码表达式构建器

样本的标记:

Text = '<%$ Code: GetText() %>'
Text = '<%$ Code: MyStaticClass.MyStaticProperty %>'
Text = '<%$ Code: DateTime.Now.ToShortDateString() %>'
MaxLenth = '<%$ Code: 30 + 40 %>'

代码表达式构建器的真正美妙之处在于,您可以像在非数据绑定情况下使用表达式一样使用数据绑定。您还可以创建执行其他功能的其他表达式生成器。

. config:

<system.web>    
    <compilation debug="true">
        <expressionBuilders>
            <add expressionPrefix="Code" type="CodeExpressionBuilder" />

实现这一切的cs类:

[ExpressionPrefix("Code")]
public class CodeExpressionBuilder : ExpressionBuilder
{
    public override CodeExpression GetCodeExpression(
        BoundPropertyEntry entry,
        object parsedData,
        ExpressionBuilderContext context)
    {            
        return new CodeSnippetExpression(entry.Expression);
    }
} 

其他回答

web.config中appsettings元素的'file'属性。

指定包含自定义应用程序配置设置的外部文件的相对路径。

如果你的应用程序设置很少,需要在不同的环境(prod)上进行修改,这是一个很好的选择。

因为网络的任何变化。配置文件会导致应用程序重新启动,使用单独的文件允许用户修改appSettings部分中的值,而不会导致应用程序重新启动。单独文件的内容与Web中的appSettings部分合并。配置文件。

我想到了一个特性,有时候你需要隐藏页面的某些部分。你可以用javascript或者下面这段简单的代码:

if (Request.Browser.Crawler){
        HideArticleComments();

将位于App_Code文件夹中的类附加到全局应用程序类文件。

ASP。NET 2.0 -全球。asax -代码背后文件。

它也可以在Visual Studio 2008中工作。

ScottGu在http://weblogs.asp.net/scottgu/archive/2006/04/03/441787.aspx上有一堆技巧

这是最好的一个。把它加到你的网里。配置更快的编译。这是3.5SP1后通过这个QFE。

<compilation optimizeCompilations="true">

Quick summary: we are introducing a new optimizeCompilations switch in ASP.NET that can greatly improve the compilation speed in some scenarios. There are some catches, so read on for more details. This switch is currently available as a QFE for 3.5SP1, and will be part of VS 2010. The ASP.NET compilation system takes a very conservative approach which causes it to wipe out any previous work that it has done any time a ‘top level’ file changes. ‘Top level’ files include anything in bin and App_Code, as well as global.asax. While this works fine for small apps, it becomes nearly unusable for very large apps. E.g. a customer was running into a case where it was taking 10 minutes to refresh a page after making any change to a ‘bin’ assembly. To ease the pain, we added an ‘optimized’ compilation mode which takes a much less conservative approach to recompilation.

通过在这里: