这个问题之所以存在,是因为它确实存在 具有历史意义,但事实并非如此 被认为是一个很好的主题问题 因为是本网站,所以请不要使用 作为证据,你可以问类似的问题 这里的问题。 更多信息:https://stackoverflow.com/faq
总有一些功能在边缘场景中很有用,但正是因为这个原因,大多数人都不知道它们。我要求的是课本上通常没有教过的特性。
你知道的是什么?
这个问题之所以存在,是因为它确实存在 具有历史意义,但事实并非如此 被认为是一个很好的主题问题 因为是本网站,所以请不要使用 作为证据,你可以问类似的问题 这里的问题。 更多信息:https://stackoverflow.com/faq
总有一些功能在边缘场景中很有用,但正是因为这个原因,大多数人都不知道它们。我要求的是课本上通常没有教过的特性。
你知道的是什么?
当前回答
可以将ASPX页面打包到一个库(.dll)中,并将它们与ASP. dll一起提供。净引擎。
您需要实现自己的VirtualPathProvider,它将通过Relfection特定的DLL加载,或者您可以在路径名中包含DLL名称。由你决定。
当覆盖VirtualFile时,奇迹发生了。方法,在其中从程序集类返回ASPX文件作为资源:Assembly. getmanifestresourcestream。ASP。NET引擎将处理资源,因为它是通过VirtualPathProvider提供的。
这允许插件页面,或者像我所做的那样,使用它来包含带有控件的HttpHandler。
其他回答
在ASP。NET v3.5添加了一些路由,你可以创建自己的友好url,只需在页面管道的早期编写HTTPModule并重写请求(如BeginRequest事件)。
像http://servername/page/Param1/SomeParams1/Param2/SomeParams2这样的url将被映射到如下所示的另一个页面(通常使用正则表达式)。
HttpContext.RewritePath("PageHandler.aspx?Param1=SomeParms1&Param2=SomeParams2");
DotNetNuke有一个非常好的HttpModule来为他们的友好url做这个。对于不能部署. net v3.5的机器仍然有用。
我的团队经常使用这个方法:
WebRequest myRequest = WebRequest.Create("http://www.google.com");
WebResponse myResponse = myRequest.GetResponse();
StreamReader sr = new StreamReader(myResponse.GetResponseStream());
// here's page's response loaded into a string for further use
String thisReturn = sr.ReadToEnd().Trim();
它以字符串的形式加载网页的响应。你也可以发送post参数。
当我们需要一些便宜和快速的东西时,我们用它来代替ASCX/AJAX/WebServices。基本上,它是一种跨服务器访问web可用内容的快速方法。事实上,我们昨天刚刚把它命名为“乡下人网络服务”。
我曾经开发过一个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检查失败并生成异常。
你知道可以用ASP。IIS或Visual Studio之外的网络?
整个运行时都打包好了,可以在任何想要尝试的进程中托管。使用ApplicationHost, HttpRuntime和HttpApplication类,你也可以打磨这些.aspx页面,并从中得到漂亮的HTML输出。
HostingClass host = ApplicationHost.CreateApplicationHost(typeof(HostingClass),
"/virtualpath", "physicalPath");
host.ProcessPage(urlToAspxFile);
你的主持课程:
public class HostingClass : MarshalByRefObject
{
public void ProcessPage(string url)
{
using (StreamWriter sw = new StreamWriter("C:\temp.html"))
{
SimpleWorkerRequest worker = new SimpleWorkerRequest(url, null, sw);
HttpRuntime.ProcessRequest(worker);
}
// Ta-dah! C:\temp.html has some html for you.
}
}
默认情况下,任何web表单页面都继承自System.Web.UI.Page类。如果您希望您的页面继承自自定义基类,继承自System.Web.UI.Page怎么办?
有一种方法可以约束任何页面从您自己的基类继承。只需在web.config中添加一行:
<system.web>
<pages pageBaseType="MyBasePageClass" />
</system.web>
注意:只有当你的类是一个独立的类时,这才有效。我的意思是一个没有隐藏代码的类,它看起来像<%@ Page Language=" c# " AutoEventWireup="true" %>