ASP ASP.NET Forms身份验证登录超时

<system.web>
    <authentication mode="Forms">
          <forms timeout="50000000"/>
    </authentication>
</system.web>

ASP asp.net内联标签

<% ... %> The most basic inline tag, basically runs normal code: 

<% if (User.IsInRole("admin")) { %> You can see this <% } else { %> You are no admin fool! <%} %> 
http://msdn2.microsoft.com/en-us/library/ms178135(vs.80).aspx 

<%= ... %> Used for small chunks of information, usually from objects and single pieces of information like a single string or int variable: 

The Date is now <%= DateTime.Now.ToShortDateString() %> The value of string1 is <%= string1 %> http://msdn2.microsoft.com/en-us/library/6dwsdcf5(VS.71).aspx 

note: <%= is the equivalent of Response.Write() - Courtesy of Adam from the US,thanks! 

<%# .. %> Used for Binding Expressions; such as Eval and Bind, most often found in data controls like GridView, Repeater, etc.: 

<asp:Repeater ID="rptMeetings" DataSourceID="meetings" runat="server"> <ItemTemplate> <%# Eval("MeetingName") %> </ItemTemplate> </asp:Repeater> 

http://msdn2.microsoft.com/en-us/library/ms178366.aspx 

<%$ ... %> Used for expressions, not code; often seen with DataSources: 

<asp:SqlDataSource ID="party" runat="server" ConnectionString="<%$ ConnectionStrings:letsParty %>" SelectCommand="SELECT * FROM table" /> http://msdn2.microsoft.com/en-us/library/d5bd1tad.aspx 

<%@ ... %> This is for directive syntax; basically the stuff you see at the top your your aspx pages like control registration and page declaration: 

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %> <%@ Register TagPrefix="wp" Namespace="CustomWebParts" %>
http://msdn2.microsoft.com/en-us/library/xz702w3e(VS.80).aspx 





<% ... %> This is a server side comment, stuff you don't want anyone without code access to see: 

<asp:Label ID="lblAwesome" runat="server" /> <% sometimes end users make me angry %> <asp:LinkButton ID="lbEdit" Text="Edit" OnClick="Edit_Click" runat="server" /> http://msdn2.microsoft.com/en-us/library/4acf8afk.aspx

ASP ASP.NET web.config安全性

Goes in order until first match found


<location>
	<system.web>
		<authorization>
			<allow roles="Admin"/>
			<deny users="*"/>
		</authorization>
	</system.web>
</location>

allow, deny

users, ex: users="Jeff"

"*" = all "?" = anonymous

ASP 探测法

<%
    ' Copyright (c) 2009, reusablecode.blogspot.com; some rights reserved.
    '
    ' This work is licensed under the Creative Commons Attribution License. To view
    ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or
    ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
    ' 94305, USA.

    ' http://en.wikipedia.org/wiki/Soundex

    ' Calculate soundex code for entire strings, and soundex digits for individual characters.
    ' REQUIRES: str_pad()
    function soundex(someString)
        dim result
        
        ' Rather than write a separate function to convert consonants to digits, I decided to overload the soundex function.
        if len(someString) = 1 then
            ' Calculate soundex digit for an individual character.
            select case lcase(someString)
            case "b", "f", "p", "v"
                soundex = "1"
            case "c", "g", "j", "k", "q", "s", "x", "z"
                soundex = "2"
            case "d", "t"
                soundex = "3"
            case "l"
                soundex = "4"
            case "m", "n"
                soundex = "5"
            case "r"
                soundex = "6"
            case else
                ' Remove vowels right away instead of during a later step.
                soundex = ""
            end select
        else
            ' Calculate soundex code for an entire string.
            
            ' The first letter remains intact.
            result = ucase(left(someString, 1))

            ' Replace consonants with digits and remove vowels.
            for i = 2 to Len(someString)
                result = result & soundex(mid(someString, i, 1))
            next
            
            ' Collapse adjacent identical digits into a single digit of that value.
            for i = 1 to 6
                do until inStr(result, cStr(i & i)) = 0
                    result = replace(result, cStr(i & i), cStr(i))
                loop
            next

            ' Return the starting letter and the first three remaining digits.
            ' If needed, append zeroes to make it a letter and three digits.
            soundex = str_pad(left(result, 4), 4, "0", STR_PAD_RIGHT)
        end if
    end function
%>

ASP 国土安全咨询系统

<%
    ' Copyright (c) 2009, reusablecode.blogspot.com; some rights reserved.
    '
    ' This work is licensed under the Creative Commons Attribution License. To view
    ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or
    ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
    ' 94305, USA.
    
    ' Obtain the current Department of Homeland Security threat level.
    function getThreatLevel()
        dim regEx
        set regEx = new RegExp
        
        with regEx
            .Pattern = ".*\n.*CONDITION=""(.*)"" />"
            .IgnoreCase = true
            .Global = true
        end with
        
        dim xmlhttp
        set xmlhttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
        xmlhttp.open "GET", "http://www.dhs.gov/dhspublic/getAdvisoryCondition", "False"
        xmlhttp.send

        getThreatLevel = regEx.replace(xmlhttp.responseText, "$1")

        set xmlhttp = nothing
        set regEx = nothing
    end function
%>

ASP 社会保障号码

<%
    ' ASP Library - Social Security Number-related functions
    '
    ' Copyright (c) 2009, reusablecode.blogspot.com; some rights reserved.
    '
    ' This work is licensed under the Creative Commons Attribution License. To view
    ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or
    ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
    ' 94305, USA.

    ' Format a Social Security Number.
    function formatSSN(byVal ssn)
        dim regEx
    
        set regEx = new RegExp
        regEx.Global = true
        regEx.Pattern = "^(\d{3})\-?(\d{2})\-?(\d{4})$"
        
        if regEx.test(ssn) then
            formatSSN = regEx.Replace(ssn, "$1-$2-$3")
        else
            Err.Raise 9
        end if
    
        set regEx = nothing
    end function
    
    ' Validate a Social Security Number.
    function isValidSSN(byVal ssn)
        dim regEx
        dim result
    
        set regEx = new RegExp
        regEx.Global = true
        regEx.Pattern = "^\d{3}\-?\d{2}\-?\d{4}$"
    
        if regEx.test(ssn) then
            result = true
        else
            result = false
        end if
        
        ' None of the digit groups can be all zeros.
        ' Area number 666 is unassigned.
        ' Numbers from 987-65-4320 to 987-65-4329 are reserved for use in advertisements.
        ' Many SSNs have been invalidated by use in advertising.
        regEx.Pattern = "^((000|666)\-?\d{2}\-?\d{4}|\d{3}\-?00\-?\d{4}|\d{3}\-?\d{2}\-?0000|987\-?65\-?432\d{1}|042\-?10\-?3580|062\-?36\-?0749|078\-?05\-?1120|095\-?07\-?3645|128\-?03\-?6045|135\-?01\-?6629|141\-?18\-?6941|165\-?(16|18|20|22|24)\-?7999|189\-?09\-?2294|212\-?09\-?(7694|9999|219\-?09\-?9999|306\-?30\-?2348|308\-?12\-?5070|468\-?28\-?8779|549\-?24\-?1889)$"
        
        if regEx.test(ssn) then
            result = false
        end if
    
        ' Numbers above 772 are currently unassigned.
        if CInt(Left(ssn, 3)) > 772 then
            result = false
        end if
        
        isValidSSN = result
        set regEx = nothing
    end function    
%>

ASP 社会保险号码

<%
    ' ASP Library - Social Insurance Number-related functions
    '
    ' Copyright (c) 2009, reusablecode.blogspot.com; some rights reserved.
    '
    ' This work is licensed under the Creative Commons Attribution License. To view
    ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or
    ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
    ' 94305, USA.

    ' Format a Social Insurance Number.
    function formatSIN(byVal socialInsuranceNumber)
        dim regEx
    
        set regEx = new RegExp
        regEx.Global = true
        regEx.Pattern = "^(\d{3})[\-\s]?(\d{3})[\-\s]?(\d{3})$"
        
        if regEx.test(socialInsuranceNumber) then
            formatSIN = regEx.Replace(socialInsuranceNumber, "$1 $2 $3")
        else
            Err.Raise 9
        end if
    
        set regEx = nothing
    end function

    ' Validate a Social Insurance Number.
    ' REQUIRES: luhn()
    function isValidSIN(byVal socialInsuranceNumber)
        dim regEx
    
        set regEx = new RegExp
        regEx.Global = true
        regEx.Pattern = "^([1-79]{3})[\-\s]?(\d{3})[\-\s]?(\d{3})$"
    
        isValidSIN = regEx.test(socialInsuranceNumber) and luhn(socialInsuranceNumber)
        set regEx = nothing
    end function

ASP ASP.net:防止页面缓存

//prevent browsers from caching the page.
Response.Cache.SetCacheability(HttpCacheability.NoCache);

#region Google cache fix (prevents google from cachine the page too long)
System.IO.FileInfo currentInfo = new System.IO.FileInfo(Request.PhysicalApplicationPath);
System.IO.FileInfo currentDirInfo = new System.IO.FileInfo(Request.PhysicalPath);

DateTime modifiedTimeToUse;
if (currentInfo.LastWriteTime > currentDirInfo.LastWriteTime)
	modifiedTimeToUse = currentInfo.LastWriteTime;
else
	modifiedTimeToUse = currentDirInfo.LastWriteTime;

Response.AppendHeader("Last-Modified", modifiedTimeToUse.ToString("ddd, dd MMM yyyy hh:mm:ss GMT"));
#endregion

ASP ASP.Net:解决Flash Cookie Bug AKA恢复会话| SWFUpload的

Global.asax:
<script RunAt="server" Language="C#">

	/* Fix for the Flash Player Cookie bug in Non-IE browsers.
* Since Flash Player always sends the IE cookies even in FireFox
* we have to bypass the cookies by sending the values as part of the POST or GET
* and overwrite the cookies with the passed in values.
*
* The theory is that at this point (BeginRequest) the cookies have not been ready by
* the Session and Authentication logic and if we update the cookies here we'll get our
* Session and Authentication restored correctly
*/
    void Application_BeginRequest(object sender, EventArgs e)
    {
		try
		{
			string session_param_name = "ASPSESSID";
			string session_cookie_name = "ASP.NET_SESSIONID";
			string session_value = Request.Form[session_param_name] ?? Request.QueryString[session_param_name];
			if (session_value != null) { UpdateCookie(session_cookie_name, session_value); }
		}
		catch (Exception) { }

		try
		{
			string auth_param_name = "AUTHID";
			string auth_cookie_name = FormsAuthentication.FormsCookieName;
			string auth_value = Request.Form[auth_param_name] ?? Request.QueryString[auth_param_name];

			if (auth_value != null) { UpdateCookie(auth_cookie_name, auth_value); }
		}
		catch (Exception) { }
    }
	void UpdateCookie(string cookie_name, string cookie_value)
	{
		HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(cookie_name);
		if (cookie == null)
		{
			HttpCookie cookie1 = new HttpCookie(cookie_name, cookie_value);
			Response.Cookies.Add(cookie1);
		}
		else
		{
			cookie.Value = cookie_value;
			HttpContext.Current.Request.Cookies.Set(cookie);
		}
	}
       
</script>

C# Page_Load:
uploader.URL = Request.Url +
				"?ASPSESSID=" + Session.SessionID +
				"&AUTHID=" + (Request.Cookies[FormsAuthentication.FormsCookieName] == null ? "" : Request.Cookies[FormsAuthentication.FormsCookieName].Value);

ASP 包含价值

function containsValue(arrayName, valueToFind)
	found = false
	for x = 0 to ubound(arrayName)
		if arrayName(x) = valueToFind then
			found = true
		end if
	next
	containsValue = found
end function