Forms Authentication - Redirecting users to a Page other than Default.aspx
来源:互联网 发布:淘宝极有家投诉 编辑:程序博客网 时间:2024/06/14 21:26
http://geekswithblogs.net/ranganh/archive/2005/04/25/37612.aspx
In this article I will explain how to redirect users to a specific page rather than the generic default.aspx upon successful authentication of the user.
While using ASP.NET Forms authentication, if we try to access a protected page, the user would be taken to the login.aspx page with the ReturnUrl parameter having the path for the originally requested page.
Once, the user's credentials are verified, the RedirectFromLoginPage method can be used to take the user back to the originally requested page.
However, if there is no specified ReturnUrl, then FormsAuthentication by default takes the user to the default.aspx page upon successful authentication.
If we do not have a default.aspx page or we want to take the users to our custom page etc., then we can use the Setauthcookie method to set the cookie and then redirect users to our desired page. The following code establishes the same.
// Once the user's entered credentials are verified //
if(Request.Params["ReturnUrl"] != null)
{
FormsAuthentication.RedirectFromLoginPage(txtUserName.text, false);
}
else
{
FormsAuthentication.SetAuthcookie(txtUserName.text, false);
Response.Redirect("CustomPage.aspx");
}
The above code first verifies whether there is any ReturnUrl parameter such that if exists, it should take to the originally requested page.
Else, it sets the authcookie and then redirects user to a custom page.
The txtUserName is the ID of the textbox which is used to capture the username.
This article applies to ASP.NET 1.0 & 1.1 Versions.
- Forms Authentication - Redirecting users to a Page other than Default.aspx
- is-there-a-way-to-test-whether-a-c-class-has-a-default-constructor-other-than
- How do i prevent end users from connecting to the database other than my application?", version 8.1.5
- How to freeze a dynamic aspx page into a static html page (on the server).
- How to freeze a dynamic aspx page into a static html page (on the server).
- Redirecting User to Login Page After Session Timeouts
- create Mailboxes using addresses other than the default
- please specify user and group other than root, pool 'default'
- select a different database(other than MySQL)
- How to use a man page Faster than a Google search
- Forms authentication without a (visible) form
- Tumblr Architecture - 15 Billion Page Views a Month and Harder to Scale than Twitter
- http://blog.hexun.com/lotus_west/default.aspx?page=3
- http://blog.hexun.com/lotus_west/default.aspx?page=3
- Close multi opener, parent of a web window and redirect to default home page
- Adding Users to Passwordfile / Using Passwordfile Authentication (Doc ID 184696.1)
- 问题记录:NameNode is still loading. Redirecting to the Startup Progress page.
- How to Make Close Other Forms Option Updatable
- 根据EBS请求ID查找输出文件及LOG在服务器的位置和路径
- S3C2440系统时钟【转】
- 道听途说Struts2之13:默认的Action
- YQL - 将 Web 作为数据库来使用的查询语言
- 处女贴
- Forms Authentication - Redirecting users to a Page other than Default.aspx
- GraphEdit使用
- textFiled要注意的地方
- 挑逗床上美女 安卓休闲游戏
- ArcGIS Runtime SDK for iOS v2.2.1发布
- 炫丽的导航特效
- JavaScript
- 安装Xampp后apache无发启动,80端口被占用
- 一个30年老交警的吐血警告