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


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

你知道的是什么?


当前回答

Page对象上的ClientScript属性。

其他回答

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

我的团队经常使用这个方法:

WebRequest myRequest = WebRequest.Create("http://www.google.com");
WebResponse myResponse = myRequest.GetResponse();
StreamReader sr = new StreamReader(myResponse.GetResponseStream());

// here's page's response loaded into a string for further use

String thisReturn = sr.ReadToEnd().Trim();

它以字符串的形式加载网页的响应。你也可以发送post参数。

当我们需要一些便宜和快速的东西时,我们用它来代替ASCX/AJAX/WebServices。基本上,它是一种跨服务器访问web可用内容的快速方法。事实上,我们昨天刚刚把它命名为“乡下人网络服务”。

ASP的一个鲜为人知和很少使用的特性。网络:

标签的映射

它很少被使用,因为只有在特定的情况下你才会需要它,但当你需要它的时候,它是如此方便。

一些关于这个小功能的文章:

ASP中的标签映射。网 在ASP中使用标签映射。NET 2.0

从上一篇文章来看:

Tag mapping allows you to swap compatible controls at compile time on every page in your web application. 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. 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:

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

HttpContext。项作为请求级缓存工具

默认情况下,自定义控件的标记之间的任何内容都被添加为子控件。这可以在AddParsedSubObject()覆盖中截获,用于过滤或额外的解析(例如,LiteralControls中的文本内容):

    protected override void AddParsedSubObject(object obj)
     { var literal = obj as LiteralControl;
       if (literal != null) Controls.Add(parseControl(literal.Text));
       else base.AddParsedSubObject(obj);
     }

...

   <uc:MyControl runat='server'>
     ...this text is parsed as a LiteralControl...
  </uc:MyControl>