这个问题之所以存在,是因为它确实存在 具有历史意义,但事实并非如此 被认为是一个很好的主题问题 因为是本网站,所以请不要使用 作为证据,你可以问类似的问题 这里的问题。 更多信息:https://stackoverflow.com/faq
总有一些功能在边缘场景中很有用,但正是因为这个原因,大多数人都不知道它们。我要求的是课本上通常没有教过的特性。
你知道的是什么?
这个问题之所以存在,是因为它确实存在 具有历史意义,但事实并非如此 被认为是一个很好的主题问题 因为是本网站,所以请不要使用 作为证据,你可以问类似的问题 这里的问题。 更多信息:https://stackoverflow.com/faq
总有一些功能在边缘场景中很有用,但正是因为这个原因,大多数人都不知道它们。我要求的是课本上通常没有教过的特性。
你知道的是什么?
当前回答
可以将ASPX页面打包到一个库(.dll)中,并将它们与ASP. dll一起提供。净引擎。
您需要实现自己的VirtualPathProvider,它将通过Relfection特定的DLL加载,或者您可以在路径名中包含DLL名称。由你决定。
当覆盖VirtualFile时,奇迹发生了。方法,在其中从程序集类返回ASPX文件作为资源:Assembly. getmanifestresourcestream。ASP。NET引擎将处理资源,因为它是通过VirtualPathProvider提供的。
这允许插件页面,或者像我所做的那样,使用它来包含带有控件的HttpHandler。
其他回答
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)
将位于App_Code文件夹中的类附加到全局应用程序类文件。
ASP。NET 2.0 -全球。asax -代码背后文件。
它也可以在Visual Studio 2008中工作。
在网站发布并部署到生产服务器后,如果我们需要对服务器端按钮进行一些更改,则单击事件。我们可以在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
}
面板中的DefaultButton属性。
它为特定面板设置默认按钮。