如何重定向到登录页面 [英] How to redirect to a login Page

查看:108
本文介绍了如何重定向到登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想了解登录网址代码.

在我的项目中,有一个登录页面,如果我登录mozilla并复制url并将其粘贴到其他网站lik chrome和IE Mean中,它将显示singin页面,即我的收件箱内容页面,但不应显示相同的页面,应显示显示我的主页(登录页面),我需要重定向登录页面,我该怎么做.


帮帮我...

Hi all ,

I want to know about login url code.

In my project i ve a login page ,if i signin in mozilla and copy the url and paste it into other website lik chrome and IE mean ,it displayed the singin page i.e my inbox content page ,but it should not display the same and should display my Home page (login page), i need to redirect the login page,how can i do this .


Help me...

推荐答案

阅读本文:

ASP.NET成员资格和角色提供者 [
Read this article:

ASP.NET Membership and Role Provider[^]

or

use this code in web.config file
<authentication mode="Forms">
     <forms cookieless="UseCookies" defaultUrl="HomePage.aspx"

    loginUrl="UnAuthorized.aspx" protection="All" timeout="30">
          </forms>
</authentication>



并使用具有以下代码的登录控制事件:



and use login control event with following code:

protected void Login1_Authenticate(object sender,AuthenticateEventArgs e)
{
 if (Membership.ValidateUser(Login1.UserName, Login1.Password) == true)
    {
        Login1.Visible = true;
        Session["user"] = User.Identity.Name;
        FormsAuthentication.RedirectFromLoginPage(Login1.UserName, true);
    }
 else
    {
        Response.Write("Invalid Login");
    }
}


检查这些博客
http://www.asp.net/mvc/tutorials/security/preventing-open-重定向攻击 [ ^ ]
http://stackoverflow.com/Questions/356982/how-to-redirect-to-a-dynamic-login-url-in-asp-net-mvc [ http://weblogs.asp. net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx [
check these blogs
http://www.asp.net/mvc/tutorials/security/preventing-open-redirection-attacks[^]
http://stackoverflow.com/questions/356982/how-to-redirect-to-a-dynamic-login-url-in-asp-net-mvc[^]
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx[^]
--NDK


谢谢大家,我使用的方法如下所示,效果很好.
Thank You all, I am using like the below, its working great.
        protected void Application_Start(object sender, EventArgs e)
        {

        }

        protected void Session_Start(object sender, EventArgs e)
        {
            Response.Redirect(Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~\\Home.aspx"));
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {
            Response.Redirect(Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~\\Home.aspx"));
        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}


这篇关于如何重定向到登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆