这个问题之所以存在,是因为它确实存在 具有历史意义,但事实并非如此 被认为是一个很好的主题问题 因为是本网站,所以请不要使用 作为证据,你可以问类似的问题 这里的问题。 更多信息:https://stackoverflow.com/faq
总有一些功能在边缘场景中很有用,但正是因为这个原因,大多数人都不知道它们。我要求的是课本上通常没有教过的特性。
你知道的是什么?
这个问题之所以存在,是因为它确实存在 具有历史意义,但事实并非如此 被认为是一个很好的主题问题 因为是本网站,所以请不要使用 作为证据,你可以问类似的问题 这里的问题。 更多信息: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)
其他回答
ScottGu在http://weblogs.asp.net/scottgu/archive/2006/04/03/441787.aspx上有一堆技巧
类似于optimizeCompilations= " true "的解决方案,这里有另一个可以加快你在构建之间等待的时间(非常好,特别是如果你正在处理一个大型项目):创建一个基于ram的驱动器(即使用RamDisk),并更改默认的“临时ASP。NET文件”到这个基于内存的驱动器。
关于如何做到这一点的完整细节在我的博客上:http://www.wagnerdanda.me/2009/11/speeding-up-build-times-in-asp-net-with-ramdisk/
基本上你首先配置一个RamDisk(同样,在我的博客中有一个免费RamDisk的链接),然后你改变你的网络。按此配置:
<system.web>
....
<compilation debug="true" tempDirectory="R:\ASP_NET_TempFiles\">
....
</compilation>
....
</system.web>
它大大增加了我的开发时间,你只需要为你的电脑投资内存:)
编程的快乐!
瓦格纳·丹达
很多人提到了如何在重新编译时优化代码。最近我发现我可以在aspx页面中完成大部分的开发(后台代码),完全跳过构建步骤。只需保存文件并刷新页面。你所要做的就是把你的代码包装在下面的标签中:
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Write("Look Ma', I didn't even had to build!")
End Sub
</script>
一旦你完成了,只要移动到代码背后,构建,测试一切工作,瞧!
-D
throw new HttpException(404, "Article not found");
这将被ASP捕获。NET,它将返回customErrors页面。在最近的.NET每日小贴士中了解了这一点
Page指令中的MaintainScrollPositionOnPostback属性。它用于在回发时保持aspx页面的滚动位置。