这个问题之所以存在,是因为它确实存在 具有历史意义,但事实并非如此 被认为是一个很好的主题问题 因为是本网站,所以请不要使用 作为证据,你可以问类似的问题 这里的问题。 更多信息:https://stackoverflow.com/faq
总有一些功能在边缘场景中很有用,但正是因为这个原因,大多数人都不知道它们。我要求的是课本上通常没有教过的特性。
你知道的是什么?
这个问题之所以存在,是因为它确实存在 具有历史意义,但事实并非如此 被认为是一个很好的主题问题 因为是本网站,所以请不要使用 作为证据,你可以问类似的问题 这里的问题。 更多信息:https://stackoverflow.com/faq
总有一些功能在边缘场景中很有用,但正是因为这个原因,大多数人都不知道它们。我要求的是课本上通常没有教过的特性。
你知道的是什么?
当前回答
类似于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>
它大大增加了我的开发时间,你只需要为你的电脑投资内存:)
编程的快乐!
瓦格纳·丹达
其他回答
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; }
}
}
}
HttpContext。IsCustomErrorEnabled是一个很酷的特性。我不止一次发现它很有用。这里有一篇关于它的短文。
ScottGu在http://weblogs.asp.net/scottgu/archive/2006/04/03/441787.aspx上有一堆技巧
使用configSource拆分配置文件。
你可以在web中使用configSource属性。将配置元素推送到其他.config文件,例如: 而不是:
<appSettings>
<add key="webServiceURL" value="https://some/ws.url" />
<!-- some more keys -->
</appSettings>
...您可以将整个appSettings部分存储在另一个配置文件中。这是新的网络。配置:
<appSettings configSource="myAppSettings.config" />
myAppSettings。配置文件:
<appSettings>
<add key="webServiceURL" value="https://some/ws.url" />
<!-- some more keys -->
</appSettings>
这对于您向客户部署应用程序并且不希望他们干扰web的场景非常有用。配置文件本身,只是希望他们能够改变只是几个设置。
裁判:http://weblogs.asp.net/fmarguerie/archive/2007/04/26/using-configsource-to-split-configuration-files.aspx
我曾经开发过一个asp.net应用程序,它通过了一家领先的安全公司的安全审计,我学会了这个简单的技巧来防止一个不太为人所知但很重要的安全漏洞。
以下解释来自: http://www.guidanceshare.com/wiki/ASP.NET_2.0_Security_Guidelines_-_Parameter_Manipulation#Consider_Using_Page.ViewStateUserKey_to_Counter_One-Click_Attacks
考虑使用Page。ViewStateUserKey用于对抗一键式攻击。如果您对调用者进行身份验证并使用ViewState,请设置Page。Page_Init事件处理程序中的ViewStateUserKey属性,以防止一键式攻击。
void Page_Init (object sender, EventArgs e) {
ViewStateUserKey = Session.SessionID;
}
将属性设置为您知道对每个用户都是唯一的值,例如会话ID、用户名或用户标识符。
A one-click attack occurs when an attacker creates a Web page (.htm or .aspx) that contains a hidden form field named __VIEWSTATE that is already filled with ViewState data. The ViewState can be generated from a page that the attacker had previously created, such as a shopping cart page with 100 items. The attacker lures an unsuspecting user into browsing to the page, and then the attacker causes the page to be sent to the server where the ViewState is valid. The server has no way of knowing that the ViewState originated from the attacker. ViewState validation and HMACs do not counter this attack because the ViewState is valid and the page is executed under the security context of the user.
通过设置ViewStateUserKey属性,当攻击者浏览到一个页面以创建ViewState时,该属性将初始化为攻击者的名字。当合法用户向服务器提交页面时,将使用攻击者的名称对页面进行初始化。结果,ViewState HMAC检查失败并生成异常。