This documentation is archived and is not being maintained.

FormsAuthentication.SetAuthCookie Method (String, Boolean, String)

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

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

Public Shared Sub SetAuthCookie ( _
	userName As String, _
	createPersistentCookie As Boolean, _
	strCookiePath As String _
Dim userName As String
Dim createPersistentCookie As Boolean
Dim strCookiePath As String

FormsAuthentication.SetAuthCookie(userName, createPersistentCookie, strCookiePath)
public static void SetAuthCookie (
	String userName, 
	boolean createPersistentCookie, 
	String strCookiePath
public static function SetAuthCookie (
	userName : String, 
	createPersistentCookie : boolean, 
	strCookiePath : String
Not applicable.



The name of an authenticated user.


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


The cookie path for the forms-authentication ticket.

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