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


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

你知道的是什么?


当前回答

HttpModules。建筑非常优雅。也许不是一个隐藏的功能,但仍然很酷。

其他回答

模板化用户控件。一旦你知道它们是如何工作的,你就会看到各种各样的可能性。下面是最简单的实现:

TemplatedControl.ascx

这里最棒的事情是使用简单而熟悉的用户控件构建块,并能够使用HTML和一些占位符来布局UI的不同部分。

<%@ Control Language="C#" CodeFile="TemplatedControl.ascx.cs" Inherits="TemplatedControl" %>

<div class="header">
    <asp:PlaceHolder ID="HeaderPlaceHolder" runat="server" />
</div>
<div class="body">
    <asp:PlaceHolder ID="BodyPlaceHolder" runat="server" />
</div>

TemplatedControl.ascx.cs

这里的“秘密”是使用ITemplate类型的公共属性,并知道[ParseChildren]和[PersistenceMode]属性。

using System.Web.UI;

[ParseChildren(true)]
public partial class TemplatedControl : System.Web.UI.UserControl
{
    [PersistenceMode(PersistenceMode.InnerProperty)]
    public ITemplate Header { get; set; }

    [PersistenceMode(PersistenceMode.InnerProperty)]
    public ITemplate Body { get; set; }

    void Page_Init()
    {
        if (Header != null)
            Header.InstantiateIn(HeaderPlaceHolder);

        if (Body != null)
            Body.InstantiateIn(BodyPlaceHolder);
    }
}

default . aspx

<%@ Register TagPrefix="uc" TagName="TemplatedControl" Src="TemplatedControl.ascx" %>

<uc:TemplatedControl runat="server">
    <Header>Lorem ipsum</Header>
    <Body>
        // You can add literal text, HTML and server controls to the templates
        <p>Hello <asp:Label runat="server" Text="world" />!</p>
    </Body>
</uc:TemplatedControl>

你甚至会得到内部模板属性的智能感知。因此,如果您在团队中工作,您可以快速创建可重用的UI,以实现与您的团队已经从内置ASP中享受到的相同的可组合性。NET服务器控件。

MSDN示例(与开头的链接相同)添加了一些额外的控件和命名容器,但只有当您希望支持“中继器类型”控件时,才需要这样做。

这是最好的一个。把它加到你的网里。配置更快的编译。这是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.

通过在这里:

类似于optimizeCompilations= " true "的解决方案,这里有另一个可以加快你在构建之间等待的时间(非常好,特别是如果你正在处理一个大型项目):创建一个基于ram的驱动器(即使用RamDisk),并更改默认的“临时ASP。NET文件”到这个基于内存的驱动器。

关于如何做到这一点的完整细节在我的博客上:http://www.wagnerdanda.me/2009/11/speeding-up-build-times-in-asp-net-with-ramdisk/

基本上你首先配置一个RamDisk(同样,在我的博客中有一个免费RamDisk的链接),然后你改变你的网络。按此配置:

 <system.web>
 ....
     <compilation debug="true" tempDirectory="R:\ASP_NET_TempFiles\">
     ....
     </compilation>
 ....
 </system.web>

它大大增加了我的开发时间,你只需要为你的电脑投资内存:)

编程的快乐!

瓦格纳·丹达

我使用的一件事是在多个版本的VB, VBScript和VB中工作。NET将记录集值转换为字符串,以消除对NULL或空白的多次测试。例如修剪(rsData(“字段名”)。值& " ") 在整数值的情况下,这将是:CLng("0" & Trim(rsData("FieldName")。值& " "))

Page对象上的ClientScript属性。