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


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

你知道的是什么?


当前回答

HttpContext.Current will always give you access to the current context's Request/Response/etc., even when you don't have access to the Page's properties (e.g., from a loosely-coupled helper class). You can continue executing code on the same page after redirecting the user to another one by calling Response.Redirect(url, false ) You don't need .ASPX files if all you want is a compiled Page (or any IHttpHandler). Just set the path and HTTP methods to point to the class in the <httpHandlers> element in the web.config file. A Page object can be retrieved from an .ASPX file programmatically by calling PageParser.GetCompiledPageInstance(virtualPath,aspxFileName,Context)

其他回答

应用程序变量可以与web应用程序一起使用,以便在整个应用程序中进行通信。它在全局中初始化。Asax文件,并在该web应用程序的页面上使用的所有用户独立于他们创建的会话。

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

基于目标浏览器设置服务器控件属性等。

<asp:Label runat="server" ID="labelText" ie:Text="这是ie文本" mozilla:Text="这是Firefox文本" 文本="这是一般文本" />

这句话让我有点吃惊。

你可以使用UniqueID属性找到任何控件:

Label label = (Label)Page.FindControl("UserControl1$Label1");

默认情况下,自定义控件的标记之间的任何内容都被添加为子控件。这可以在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>