HTTPS://MSDN.MICROSOFT.COM/ZH-CN/LIBRARY/8A22T5T3 (v=vs.80)
Formsauthentication.getredirecturl method. NET Framework 2.0Other versions
Returns the redirect URL that caused the original request to be redirected to the login page.
namespaces: System.Web.Security
Assemblies: System.Web (in System.Web.dll)
GrammarC#c++vb
public static string Getredirecturl (String Username,bool createpersistentcookie)
J #
public static string Getredirecturl (String UserName, Boolean createPersistentCookie)
Jscript
public static function Getredirecturl (username:string, Createpersistentcookie:boolean): String
Parameters
-
UserName
-
The name of the authenticated user.
-
createPersistentCookie
-
Ignore this parameter.
Returns the value of a string that contains the redirect URL.Notes
Use this method when you want to perform redirects in your application code, rather than using the RedirectFromLoginPage method.
The Getredirecturl method returns the URL specified in the query string using the ReturnURL variable name. For example, at URL http://www.contoso.com/login.aspx? ReturnUrl=caller.aspx , theGetredirecturl method returns the return URL caller.aspx. If the ReturnURL variable does not exist, theGetredirecturl method returns the URL in the Defaulturl property.
When the browser is redirected to the login page, ASP. NET will automatically add the return URL.
By default, theReturnUrl variable must refer to a page in the current application. If ReturnUrl references a page in another application or other server, theGetredirecturl method returns the URL in the defaulturl property. If you want to allow the return URL to reference a page other than the current application, you must use the enablecrossappredirects property of the forms configuration Element (Attribute) to enablecrossappredirects the property ( property) is set to true.
| Safety note |
|
Setting the enablecrossappredirects property to true to allow cross-application redirection is a potential security threat. If you allow cross-application redirection, your site will be vulnerable to malicious Web sites that use your landing page to convince your site users that the pages on the site they are using are secure. To improve security when using cross-application redirection, you should override the Getredirecturl method to allow redirection only to the licensed Web site. |
Example
The following code example redirects the authenticated user to the URL returned by the Getredirecturl method.
C#vb
<%@ page language= "C #"%><%@ Import namespace= "System.Web.Security"%><script runat= "Server" > private void Login_click (Object sender, EventArgs e) {//Create a custom formsauthenticationticket containing//a Pplication specific data for the user. string username = Usernametextbox.text; string password = Userpasstextbox.text; bool ispersistent = persistcheckbox.checked; if (Membership.ValidateUser (username, password)) {string userData = "Applicationspecific data for this user."; FormsAuthenticationTicket ticket = new FormsAuthenticationTicket (1, username, DateTime.Now, datet Ime. Now.addminutes (+), ispersistent, UserData, Formsauthentication.formscookiepath); Encrypt the ticket. String encticket = Formsauthentication.encrypt (ticket); Create the cookie. RESPONSE.COOKIES.ADD (New HttpCookie (Formsauthentication.formscookiename, Encticket)); Redirect backto original URL. Response.Redirect (Formsauthentication.getredirecturl (username, ispersistent)); } else {Msg.text = "Login failed. Please check your user name and password and try again. ";}} </script>PlatformWindows 98, Windows SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Window S XP SP2, Windows XP Starter Edition
The. NET Framework does not provide support for all versions of each platform. For a list of supported versions, see System requirements.
Formsauthentication.getredirecturl method