这个问题之所以存在,是因为它确实存在 具有历史意义,但事实并非如此 被认为是一个很好的主题问题 因为是本网站,所以请不要使用 作为证据,你可以问类似的问题 这里的问题。 更多信息:https://stackoverflow.com/faq
总有一些功能在边缘场景中很有用,但正是因为这个原因,大多数人都不知道它们。我要求的是课本上通常没有教过的特性。
你知道的是什么?
这个问题之所以存在,是因为它确实存在 具有历史意义,但事实并非如此 被认为是一个很好的主题问题 因为是本网站,所以请不要使用 作为证据,你可以问类似的问题 这里的问题。 更多信息:https://stackoverflow.com/faq
总有一些功能在边缘场景中很有用,但正是因为这个原因,大多数人都不知道它们。我要求的是课本上通常没有教过的特性。
你知道的是什么?
当前回答
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>
其他回答
ASHX文件类型的使用: 如果你只想输出一些基本的html或xml,而不想通过页面事件处理程序,那么你可以用一种简单的方式实现HttpModule
将页面命名为SomeHandlerPage。Ashx和只是把下面的代码(只有一行)
<%@ webhandler language="C#" class="MyNamespace.MyHandler" %>
然后是代码文件
using System;
using System.IO;
using System.Web;
namespace MyNamespace
{
public class MyHandler: IHttpHandler
{
public void ProcessRequest (HttpContext context)
{
context.Response.ContentType = "text/xml";
string myString = SomeLibrary.SomeClass.SomeMethod();
context.Response.Write(myString);
}
public bool IsReusable
{
get { return true; }
}
}
}
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>
在网站发布并部署到生产服务器后,如果我们需要对服务器端按钮进行一些更改,则单击事件。我们可以在aspx页面本身中使用new关键字来覆盖现有的click事件。
例子
代码背后方法
Protected void button_click(sender object, e System.EventArgs)
{
Response.Write("Look Ma', I Am code behind code!")
}
覆盖方法:
<script runat="server">
Protected void new button_click(sender object, e System.EventArgs)
{
Response.Write("Look Ma', I am overrided method!")
}
</script
通过这种方式,我们可以轻松地修复生产服务器错误,而无需重新部署。
在开始一个长时间运行的任务之前,检查客户端是否仍然连接:
if (this.Response.IsClientConnected)
{
// long-running task
}
Page对象上的ClientScript属性。