登录和母版页 [英] log in and master page

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

问题描述

大家好,



我想问一下使用母版页。我正在处理归档Web应用程序,所以我jad web应用程序与主页包含根菜单到不同的页面。我想在访问应用程序中的任何页面之前强制登录

解决方案

请按照以下链接:

https://msdn.microsoft.com/en-us/library/vstudio/ehszf8ax(v = VS.100)的.aspx [< a href =https://msdn.microsoft.com/en-us/library/vstudio/ehszf8ax(v=vs.100).aspx\"target =_ blanktitle =New Window> ^ ]



初学者教程ASP.NET中的母版页 [ ^ ]


在web.config文件中,添加thi s $ / b


system.web>

< compilation debug =truetargetFramework =4.0/>

< authentication mode =Forms>

< forms loginUrl =〜/ LoginPage.aspxtimeout =2880>< / forms>

< / authentication>

<授权>

< deny users =?/>

< allow users =*/>

< / authorization>

< /system.web>



请记住始终先拒绝用户标签,然后再按允许用户标签。



添加新的网页名称为Login.aspx。为用户名和密码添加两个文本框。如果密码错误,请添加一个按钮和一个Lable以显示错误。



在Login.aspx.cs文件中,将此代码写入button1_click事件



 使用 System.Web.Security; 
使用 System.Drawing;
受保护 void Button1_Click( object sender,EventArgs e)
{
string usr = TextBox1.Text.Trim()。ToUpper();
string psswrd = TextBox2.Text;

if (usr == 123&& psswrd == 123
{
FormsAuthentication.SetAuthCookie(usr, false );
string retrnUrl = Request.QueryString [ RETURNURL];
if (!string.IsNullOrEmpty(retrnUrl))
{
Response.Redirect(retrnUrl);
}
else
{
Response.Redirect( HomePage.aspx);
}
}
其他
Label1.Text = 用户名或密码错误;
Label1.ForeColor = Color.Red;

}





你已经完成..!



尝试打开任何页面,它会显示登录页面。如果且仅当登录成功,那么它会将您重定向到原始请求页面.Hurrey ..享受.. !!



您可以使用以下代码退出。



 FormsAuthentication.SignOut(); 
Response.Redirect( Login.aspx);


hi everybody ,,

i want to ask about using master page. i am work on archiving web application so i lad web application with master page contains rooted menu to different pages. i want to force log in before accessing any page in the application

解决方案

Follow these links:
https://msdn.microsoft.com/en-us/library/vstudio/ehszf8ax(v=vs.100).aspx[^]

Beginner's Tutorial on Master Pages in ASP.NET[^]


IN web.config file, add this

system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Forms">
<forms loginUrl="~/LoginPage.aspx" timeout="2880"></forms>
</authentication>
<authorization>
<deny users="?"/>
<allow users="*"/>
</authorization>
</system.web>

Remember always "deny user" tag first then followed by "allow User" tag.

Add a new webPage name it Login.aspx. Add two text boxes for user name and Password. Add One Button and one Lable to show error if wrong password.

In Login.aspx.cs file, write this code in button1_click event

using System.Web.Security;
using System.Drawing;
protected void Button1_Click(object sender, EventArgs e)
        {
            string usr = TextBox1.Text.Trim().ToUpper();
            string psswrd = TextBox2.Text;

            if (usr == "123" && psswrd == "123")
            {
                FormsAuthentication.SetAuthCookie(usr, false);
                string retrnUrl = Request.QueryString["returnUrl"];
                if (!string.IsNullOrEmpty(retrnUrl))
                {
                    Response.Redirect(retrnUrl);
                }
                else
                {
                    Response.Redirect("HomePage.aspx");
                }
            }
            else
                Label1.Text = "User name or password is wrong";
            Label1.ForeColor = Color.Red;

        }



You are done..!

Try to open any page, it will show you Login Page. If and only if login success, then it will redirect you to original requested page.. Hurrey.. enjoy..!!

You can use below code to sign out.

FormsAuthentication.SignOut();
            Response.Redirect("Login.aspx");


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

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