ASP.NET的隐藏功能[关闭]

本文翻译自:Hidden Features of ASP.NET [closed]

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. 这个问题之所以存在,是因为它具有历史意义,但对于本网站而言,它不被认为是一个好的,主题上的问题, 因此请不要将其作为您可以在此处提出类似问题的证据。

More info: https://stackoverflow.com/faq 更多信息: https//stackoverflow.com/faq


There are always features that would be useful in fringe scenarios, but for that very reason most people don't know them. 总有一些功能在边缘场景中很有用,但正因如此,大多数人都不了解它们。 I am asking for features that are not typically taught by the text books. 我要求的是教科书通常不会教授的功能。

What are the ones that you know? 你知道的是什么?


#1楼

参考:https://stackoom.com/question/EHx/ASP-NET的隐藏功能-关闭


#2楼

Here's the best one. 这是最好的一个。 Add this to your web.config for MUCH faster compilation. 将其添加到您的web.config中,以便更快地进行编译。 This is post 3.5SP1 via this QFE . 这是通过此QFE发布的3.5SP1。

<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. 快速摘要:我们在ASP.NET中引入了一个新的optimizeCompilations开关,可以在某些情况下大大提高编译速度。 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. 此交换机目前可作为3.5SP1的QFE使用,并将成为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. ASP.NET编译系统采用了一种非常保守的方法,这种方法可以消除它在“顶级”文件发生变化时所做的任何先前的工作。 'Top level' files include anything in bin and App_Code, as well as global.asax. “顶级”文件包括bin和App_Code中的任何内容,以及global.asax。 While this works fine for small apps, it becomes nearly unusable for very large apps. 虽然这适用于小型应用程序,但它对于非常大的应用程序几乎无法使用。 Eg 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. 例如,客户遇到了一个案例,在对“bin”程序集进行任何更改后,需要花费10分钟来刷新页面。

To ease the pain, we added an 'optimized' compilation mode which takes a much less conservative approach to recompilation. 为了减轻痛苦,我们添加了一个“优化的”编译模式,它采用了一种不那么保守的重新编译方法。

Via here : 通过这里


#3楼

WebMethods. 的WebMethods。

You can using ASP.NET AJAX callbacks to web methods placed in ASPX pages. 您可以将ASP.NET AJAX回调用于放置在ASPX页面中的Web方法。 You can decorate a static method with the [WebMethod()] and [ScriptMethod()] attributes. 您可以使用[WebMethod()]和[ScriptMethod()]属性修饰静态方法。 For example: 例如:

[System.Web.Services.WebMethod()] 
[System.Web.Script.Services.ScriptMethod()] 
public static List<string> GetFruitBeginingWith(string letter)
{
    List<string> products = new List<string>() 
    { 
        "Apple", "Banana", "Blackberry", "Blueberries", "Orange", "Mango", "Melon", "Peach"
    };

    return products.Where(p => p.StartsWith(letter)).ToList();
}

Now, in your ASPX page you can do this: 现在,在ASPX页面中,您可以执行以下操作:

<form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />
        <input type="button" value="Get Fruit" onclick="GetFruit('B')" />
    </div>
</form>

And call your server side method via JavaScript using: 并使用以下命令通过JavaScript调用服务器端方法:

    <script type="text/javascript">
    function GetFruit(l)
    {
        PageMethods.GetFruitBeginingWith(l, OnGetFruitComplete);
    }

    function OnGetFruitComplete(result)
    {
        alert("You got fruit: " + result);
    }
</script>

#4楼

One little known and rarely used feature of ASP.NET is: ASP.NET的一个鲜为人知且很少使用的特性是:

Tag Mapping 标记映射

It's rarely used because there's only a specific situation where you'd need it, but when you need it, it's so handy. 它很少使用,因为只有你需要它的特定情况,但是当你需要它时,它是如此方便。

Some articles about this little know feature: 一些关于这个小知识的文章:

Tag Mapping in ASP.NET ASP.NET中的标记映射
Using Tag Mapping in ASP.NET 2.0 在ASP.NET 2.0中使用标记映射

and from that last article: 从上一篇文章:

Tag mapping allows you to swap compatible controls at compile time on every page in your web application. 标记映射允许您在编译时在Web应用程序的每个页面上交换兼容的控件。 A useful example is if you have a stock ASP.NET control, such as a DropDownList, and you want to replace it with a customized control that is derived from DropDownList. 一个有用的示例是,如果您有一个库存ASP.NET控件,例如DropDownList,并且您希望将其替换为从DropDownList派生的自定义控件。 This could be a control that has been customized to provide more optimized caching of lookup data. 这可以是一个定制的控件,以提供更优化的查找数据缓存。 Instead of editing every web form and replacing the built in DropDownLists with your custom version, you can have ASP.NET in effect do it for you by modifying web.config: 您可以通过修改web.config来实现ASP.NET,而不是编辑每个Web表单并使用您的自定义版本替换内置的DropDownLists:

<pages>
 <tagMapping>
   <clear />
   <add tagType="System.Web.UI.WebControls.DropDownList"
        mappedTagType="SmartDropDown"/>
  </tagMapping>
</pages>

#5楼

DefaultButton property in Panels. Panels中的DefaultButton属性。

It sets default button for a particular panel. 它为特定面板设置默认按钮。


#6楼

MaintainScrollPositionOnPostback attribute in Page directive. Page指令中的MaintainScrollPositionOnPostback属性。 It is used to maintain scroll position of aspx page across postbacks. 它用于在回发中维护aspx页面的滚动位置。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值