这个问题之所以存在,是因为它确实存在 具有历史意义,但事实并非如此 被认为是一个很好的主题问题 因为是本网站,所以请不要使用 作为证据,你可以问类似的问题 这里的问题。 更多信息:https://stackoverflow.com/faq
总有一些功能在边缘场景中很有用,但正是因为这个原因,大多数人都不知道它们。我要求的是课本上通常没有教过的特性。
你知道的是什么?
这个问题之所以存在,是因为它确实存在 具有历史意义,但事实并非如此 被认为是一个很好的主题问题 因为是本网站,所以请不要使用 作为证据,你可以问类似的问题 这里的问题。 更多信息:https://stackoverflow.com/faq
总有一些功能在边缘场景中很有用,但正是因为这个原因,大多数人都不知道它们。我要求的是课本上通常没有教过的特性。
你知道的是什么?
当前回答
HttpContext。项作为请求级缓存工具
其他回答
throw new HttpException(404, "Article not found");
这将被ASP捕获。NET,它将返回customErrors页面。在最近的.NET每日小贴士中了解了这一点
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)
在内容页中为masterpage启用智能感知 我敢肯定这是一个鲜为人知的黑客
大多数情况下,当你想要使用母版页中的控件时,你必须使用findcontrol方法并从内容页中转换它们,MasterType指令将在visual studio中启用智能感知
只需在页面上再添加一条指令
<%@ MasterType VirtualPath="~/Masters/MyMainMasterPage.master" %>
如果您不想使用虚拟路径,则使用类名
<%@ MasterType TypeName="MyMainMasterPage" %>
点击这里获取全文
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>
我使用的一件事是在多个版本的VB, VBScript和VB中工作。NET将记录集值转换为字符串,以消除对NULL或空白的多次测试。例如修剪(rsData(“字段名”)。值& " ") 在整数值的情况下,这将是:CLng("0" & Trim(rsData("FieldName")。值& " "))