FormsAuthentication.SetAuthCookie Method (String, Boolean)

Creates an authentication ticket for the supplied user name and adds it to the cookies collection of the response or the URL.

Namespace: System.Web.Security
Assembly: System.Web (in system.web.dll)

public static void SetAuthCookie (
	string userName,
	bool createPersistentCookie
public static void SetAuthCookie (
	String userName, 
	boolean createPersistentCookie
public static function SetAuthCookie (
	userName : String, 
	createPersistentCookie : boolean
Not applicable.



The name of an authenticated user. This does not have to map to a Windows account.


true to create a durable cookie (one that is saved across browser sessions); otherwise, false.

Exception typeCondition


RequireSSL is true and IsSecureConnection is false.

The SetAuthCookie method adds a forms-authentication ticket to either the cookies collection or the URL if CookiesSupported is false. The forms-authentication ticket supplies forms-authentication information to the next request made by the browser. With forms authentication, you can use the SetAuthCookie method when you want to authenticate a user but still retain control of the navigation with redirects.

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0