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


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

你知道的是什么?


当前回答

当我将xmlDocument()转储到标签中并使用它的xsl转换显示时,我认为这很整洁。

其他回答

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

CompilationMode="Never"是一个在某些ASP中至关重要的特性。网网站。

如果你有ASP。在asp.net应用程序中,ASPX页面经常通过CMS或其他发布系统生成和更新,使用CompilationMode="Never"是很重要的。

如果没有此设置,ASPX文件更改将触发重新编译,这将快速使您的appdomain重新启动。这可以清除会话状态和httpruntime缓存,更不用说重新编译引起的延迟。

(为了防止重新编译,你可以增加numRecompilesBeforeAppRestart设置,但这不是理想的,因为它会消耗更多的内存。)

这个特性需要注意的一点是,ASPX页面不能包含任何代码块。为了解决这个问题,可以在自定义控件和/或基类中放置代码。

在ASPX页面不经常更改的情况下,这个特性基本无关紧要。

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>

If you use web services instead WCF services, you can still use standard .Net membership to enforce authentication and login session behaviour on a set web services similarly to a how you would secure web site with membership forms authentication & without the need for a special session and/or soap headers implementations by simply calling System.Web.Security.FormsAuthentication.SetAuthCookie(userName, false) [after calling Membership.ValidateUser(userName, password) of course] to create cookie in the response as if the user has logged in via a web form. Then you can retrieve this authentication cookie with Response.Cookies[].Value and return it as a string to the user which can be used to authenticate the user in subsequent calls by re-creating the cookie in the Application_BeginRequest by extracting the cookie method call param from the Request.InputStream and re-creating the auth cookie before the membership authenticates the request this way the membership provider gets tricked and will know the request is authenticated and enforce all its rules.

将此cookie返回给用户的示例web方法签名如下: 字符串登录(用户名、密码)

后续web方法调用示例如下: 字符串DoSomething(字符串authcookie,字符串methodParam1,int methodParam2等,等),你需要提取authcookie(这是从登录方法获得的值)参数从请求。InputStreamis

这也模拟了一个登录会话并调用FormsAuthentication。签出在web方法,如注销(authcookie)将 使用户需要再次登录。

有两件事在我脑海中浮现:

1)你可以在代码中打开和关闭Trace:

#ifdef DEBUG 
   if (Context.Request.QueryString["DoTrace"] == "true")
                {
                    Trace.IsEnabled = true;
                    Trace.Write("Application:TraceStarted");
                }
#endif

2)您可以使用一个共享的“代码隐藏”文件构建多个.aspx页面。

构建一个类.cs文件:

public class Class1:System.Web.UI.Page
    {
        public TextBox tbLogin;

        protected void Page_Load(object sender, EventArgs e)
        {

          if (tbLogin!=null)
            tbLogin.Text = "Hello World";
        }
    }

然后你可以有任意数量的。aspx页面(在你删除VS生成的。designer.cs和。cs代码之后):

  <%@ Page Language="C#"  AutoEventWireup="true"  Inherits="Namespace.Class1" %>
     <form id="form1" runat="server">
     <div>
     <asp:TextBox  ID="tbLogin" runat="server"></asp: TextBox  >
     </div>
     </form>

你可以在ASPX中拥有没有在Class1中出现的控件,反之亦然,但是你需要记住检查你的控件是否为空。