FormsAuthentication.GetRedirectUrl 方法
https://msdn.microsoft.com/zh-cn/library/8a22t5t3(v=vs.80)
FormsAuthentication.GetRedirectUrl 方法
返回导致重定向到登录页的原始请求的重定向 URL。
命名空间:System.Web.Security
程序集:System.Web(在 system.web.dll 中)
public static String GetRedirectUrl (
String userName,
boolean createPersistentCookie
)
public static function GetRedirectUrl (
userName : String,
createPersistentCookie : boolean
) : String
参数
- userName
-
已验证身份的用户的名称。
- createPersistentCookie
-
忽略此参数。
返回值
一个字符串,其中包含重定向 URL。
当您希望在应用程序代码中执行重定向时可使用此方法,而不使用 RedirectFromLoginPage 方法。
GetRedirectUrl 方法返回查询字符串中使用 ReturnURL 变量名指定的 URL。例如,在 URL http://www.contoso.com/login.aspx?ReturnUrl=caller.aspx 中,GetRedirectUrl 方法返回返回 URL caller.aspx。如果 ReturnURL 变量不存在,GetRedirectUrl 方法将返回DefaultUrl 属性中的 URL。
当浏览器重定向到登录页时,ASP.NET 将自动添加返回 URL。
默认情况下,ReturnUrl 变量必须引用当前应用程序中的页。如果 ReturnUrl 引用其他应用程序或其他服务器中的页,GetRedirectUrl 方法将返回DefaultUrl 属性中的 URL。如果希望允许返回 URL 引用当前应用程序以外的页,必须使用 forms 配置元素的 enableCrossAppRedirects 属性 (Attribute) 将 EnableCrossAppRedirects 属性 (Property) 设置为 true。
安全注意 |
|---|
|
将 EnableCrossAppRedirects 属性设置为 true 以允许跨应用程序重定向是一个潜在的安全威胁。如果允许跨应用程序重定向,您的站点将易于受到恶意网站的攻击,这些恶意网站将利用您的登录页使您的网站用户相信他们所使用的站点上的网页是安全的。若要提高使用跨应用程序重定向时的安全性,应该重写 GetRedirectUrl 方法,只允许重定向到许可的网站。 |
下面的代码示例将通过身份验证的用户重定向到由 GetRedirectUrl 方法返回的 URL。
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>
<script runat="server"> private void Login_Click(Object sender, EventArgs e)
{
// Create a custom FormsAuthenticationTicket containing
// application 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,
DateTime.Now.AddMinutes(30),
isPersistent,
userData,
FormsAuthentication.FormsCookiePath); // Encrypt the ticket.
string encTicket = FormsAuthentication.Encrypt(ticket); // Create the cookie.
Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket)); // Redirect back to original URL.
Response.Redirect(FormsAuthentication.GetRedirectUrl(username, isPersistent));
}
else
{
Msg.Text = "Login failed. Please check your user name and password and try again.";
}
} </script>
<html>
<head>
<title>Forms Authentication Login</title>
</head>
<body>
<form runat="server">
<span style="BACKGROUND: #80ff80">
<h3>Login Page</h3>
</span>
<asp:Label id="Msg" ForeColor="maroon" runat="server" /><P>
<table border=0>
<tbody>
<tr>
<td>Username:</td>
<td><asp:TextBox id="UserNameTextBox" type="text" runat="server" /></td>
<td>
<asp:RequiredFieldValidator id="RequiredFieldValidator1"
runat="server" ErrorMessage="*"
Display="Static"
ControlToValidate="UserNameTextBox" />
</td>
</tr>
<tr>
<td>Password:</td>
<td><asp:TextBox id="UserPassTextBox" TextMode="Password" runat="server" /></td>
<td>
<asp:RequiredFieldValidator id="RequiredFieldValidator2"
runat="server" ErrorMessage="*"
Display="Static"
ControlToValidate="UserPassTextBox" />
</td>
</tr>
<tr>
<td>Check here if this is <u>not</u><br>a public computer:</td>
<td><asp:CheckBox id="PersistCheckBox" runat="server" autopostback="true" /></td>
</tr>
</tbody>
</table>
<input type="submit" value="Login" runat="server" onserverclick="Login_Click" />
</form>
</body>
</html>
FormsAuthentication.GetRedirectUrl 方法的更多相关文章
- 自己实现FormsAuthentication.SetAuthCookie方法,怎样在ASP.NET服务端代码中删除客户端Cookie
如何手动设置AuthCookie ASP.NET中实现可以自己实现FormsAuthentication.SetAuthCookie方法,控制更为灵活 /// <summary> /// ...
- FormsAuthentication.SetAuthCookie 方法登录
FormsAuthentication.SetAuthCookie 方法,登录的原理. FormsAuthentication.SetAuthCookie 方法登录的过期时间. 登录相关阅读 asp. ...
- FormsAuthentication.HashPasswordForStoringInConfigFile 方法 之研究
摘自:http://time-is-life.cnblogs.com/articles/322523.html 给定标识哈希类型的密码和字符串,该例程产生一个适合存储在配置文件中的哈希密码. [C#] ...
- FormsAuthentication.HashPasswordForStoringInConfigFile方法再.net core中的替代代码
FormsAuthentication.HashPasswordForStoringInConfigFile()这个加密方法再.net core中不存在了,可以用下面的方式达到一样的加密效果 usin ...
- asp.net 登陆验证 Form表单验证的3种方式 FormsAuthentication.SetAuthCookie;FormsAuthentication.RedirectFromLoginPage;FormsAuthenticationTicket
我们在登陆成功后,使用下面的3种方法,都是同一个目的:创建身份验证票并将其附加到 Cookie, 当我们用Forms认证方式的时候,可以使用HttpContext.Current.User.Ident ...
- ASP.NET中身份验证的三种方法
Asp.net的身份验证有有三种,分别是"Windows | Forms | Passport",其中又以Forms验证用的最多,也最灵活.Forms 验证方式对基于用户的验证授权 ...
- asp.net中使用基于角色role的Forms验证
http://www.cnblogs.com/yao/archive/2006/06/24/434783.html asp.net中使用基于角色role的Forms验证,大致经过几下四步:1.配置系统 ...
- ASP.NET身份验证
Asp.net的身份验证有有三种,分别是"Windows | Forms | Passport",其中又以Forms验 证用的最多,也最灵活. Forms 验证方式对基于用户的验证 ...
- 经典FormsAuthenticationTicket 分析
Asp.net中基于Forms验证的角色验证授权 Asp.net的身份验证有有三种,分别是"Windows | Forms | Passport",其中又以Forms验证用的最多, ...
随机推荐
- allegro添加多个过孔
place--Via arrays matrix: [数] 矩阵:模型:[生物][地质] 基质:母体:子宫:[地质] 脉石 boundary:边界:范围:分界线 unplaced : adj. 未受到 ...
- NFC(7)向NFC硬件写入数据的两个示例(nfc硬件启动android应用,nfc硬件打开uri)
向NFC标签写入数据基本步骤 1,获取Tag对象 Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); 2,判断NFC标签的数据类型(通 ...
- WINCE6.0+IMX515通过cfimager.exe烧录镜像文件
WINCE6.0+IMX515通过cfimager.exe烧录镜像文件 freescale提供了cfimager.exe工具,可在SD/MMC卡中烧录系统镜像文件和创建FAT文件,这样,我们可以不需要 ...
- python操作Excel读--使用xlrd
一.安装xlrd模块 到python官网下载http://pypi.python.org/pypi/xlrd模块安装,前提是已经安装了python 环境. 二.使用介绍 1.导入模块 import x ...
- poj 3007 Organize Your Train part II(二叉排序树)
题目:http://poj.org/problem?id=3007 题意:按照图示的改变字符串,问有多少种..字符串.. 思路:分几种排序的方法,,刚开始用map 超时(map效率不高啊..),后来搜 ...
- oracle11g dataguard部署指南
一.Oracle11DB+DG配置 1. 单机环境介绍(PRIMARY DATABASE) 主库 primary public ip 192.168.0.252 ...
- 【jQuery】jQuery操作<input>的聚焦与全选其内容
实现效果: 源代码: $(function() { $("#exist_code_remind").attr("style","display:non ...
- Serv-U软件在64位操作系统下使用不了odbc解决方法
这是因为64位Windows上有两个ODBC连接,你需要创建一个32位的ODBC连接.打开32位ODBC管理器的位置 X:\Windows\syswow64\odbcad32.exe. 利用这个管理器 ...
- memcached性能监控
在上文“在Windows .NET平台下使用Memcached”中,我给大家介绍了如何在Windows平台上部署Memecached服务端,如何在.NET平台中应用Memcached,详细介绍了两种流 ...
- Skyline学习教程
转自:http://yunjinzh.blog.sohu.com/165279318.html 当初开设这个blog的初衷就是将PPT与专业技术进行结合 将专业技术的介绍更加艺术化 但是之前一直都没有 ...
安全注意