本文介绍了某些页面的密码保护的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不会只保护我们的站点asp.net页面,而不是所有站点,但是当我通过webconfig文件进行保护时,它将保护我的域,即,当浏览我的站点然后询问密码时,我不会在这里放置代码我使用的是webconfig文件
I wont to protect our site only asp.net pages not all the site but when i protect through webconfig file then its protect my domain i.e when browse my site then ask password that i don''t wont here i place our code which i use webconfig file
<authentication mode="Forms">
<forms loginUrl="~/upload/Default.aspx">
</forms>
br mode="hold" /> <authorization>
<deny users="?">
br mode="hold" /></deny></authorization></authentication>
而我的默认页面代码是
and my Default page code is
protected void Login1_Authenticate(object sender, System.Web.UI.WebControls.AuthenticateEventArgs e)
{
string username;
string pwd;
string CurrentUser = "";
string CurrentPwd = "";
bool LoginStatus = false;
username = Login1.UserName;
pwd = Login1.Password;
XmlDocument xd = new XmlDocument();
xd.Load(Server.MapPath("~/App_Data/AllUser.xml"));
XmlNodeList xnl = xd.GetElementsByTagName("User");
foreach (XmlNode xn in xnl)
{
XmlNodeList cxnl = xn.ChildNodes;
foreach (XmlNode cxn in cxnl)
{
if (cxn.Name == "username")
{
if (cxn.InnerText == username)
{
CurrentUser = username;
}
}
if (cxn.Name == "password")
{
if (cxn.InnerText == pwd)
{
CurrentPwd = pwd;
}
}
}
if ((CurrentUser != "") & (CurrentPwd != ""))
{
LoginStatus = true;
}
}
if (LoginStatus == true)
{
Session["UserAuthentication"] = username;
Session.Timeout = 1;
FormsAuthentication.RedirectFromLoginPage(username, true);
// Response.Redirect("upload.aspx");
}
else
{
Session["UserAuthentication"] = "";
}
}
推荐答案
<location path="<the path you want to bypass authentication>">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location></location>
在web.config文件中
in the web.config file
这篇关于某些页面的密码保护的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!