这个问题之所以存在,是因为它确实存在 具有历史意义,但事实并非如此 被认为是一个很好的主题问题 因为是本网站,所以请不要使用 作为证据,你可以问类似的问题 这里的问题。 更多信息:https://stackoverflow.com/faq


总有一些功能在边缘场景中很有用,但正是因为这个原因,大多数人都不知道它们。我要求的是课本上通常没有教过的特性。

你知道的是什么?


当前回答

我想到了一个特性,有时候你需要隐藏页面的某些部分。你可以用javascript或者下面这段简单的代码:

if (Request.Browser.Crawler){
        HideArticleComments();

其他回答

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)

当我将xmlDocument()转储到标签中并使用它的xsl转换显示时,我认为这很整洁。

我使用的一件事是在多个版本的VB, VBScript和VB中工作。NET将记录集值转换为字符串,以消除对NULL或空白的多次测试。例如修剪(rsData(“字段名”)。值& " ") 在整数值的情况下,这将是:CLng("0" & Trim(rsData("FieldName")。值& " "))

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; }
        }
    }
}

请求。IsLocal属性:

它指示当前请求是否来自本地计算机。

if( Request.IsLocal )
{
   LoadLocalAdminMailSettings();
}
else
{
   LoadServerAdminMailSettings();
}