在数据库中保存XML数据时出现问题 [英] Problem in saving XML data in database

查看:52
本文介绍了在数据库中保存XML数据时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是ASp.NET的新用户.我只是在冲浪,很好奇我如何以XML格式存储数据库之类的信息,后来又在登录目的类型示例中使用它.

Hi I am a new user of ASp.NET. I was just surfing and was curious to know how i can store information like a database in XML and later use it in Login purpose type example.

推荐答案

我从中了解到您的问题是要使用XML文件登录ASP.NET网站. XML文件包含登录用户名-密码信息,您想将其用于身份验证.如果是这样,请查看以下内容:
视频:如何使用ASP.NET从XML文件中提取数据 [使用C#在ASP.NET中使用XML文件登录 [使用XML在ASP.NET中进行表单身份验证 [
What I understand from your question is you want to login into a ASP.NET website making use of a XML file. XML file contains login username-password information and you want to use it for authentication. If so, look at the following:
Video: How To Pull Data From An XML File Using ASP.NET[^]
Login using XML file in ASP.NET using C#[^]
Form Authentication in ASP.NET using XML[^]

Sample:
LoginData.xml
<?xml version="1.0" encoding="utf-8" ?>
<employee>
<User>
<username>bikrantsingh</username>
<password>bikrant123</password>
</User>
<User>
<username>anuragsingh</username>
<password>anurag</password>
</User>
<User>
<username>saurabh</username>
<password>saurabh123</password>
</User>
</employee>



背后的代码:



Code behind:

protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
string username;
string pwd;
string CurrentUser = "";
string CurrentPwd = "";
bool LoginStatus = false;
username = Login1.UserName;
pwd = Login1.Password;
XmlDocument xmxdoc = new XmlDocument();
xmxdoc.Load(Server.MapPath("~/App_Data/Loginxml.xml"));
XmlNodeList xmlnodelist = xmxdoc.GetElementsByTagName("User");
foreach (XmlNode xn in xmlnodelist)
{
XmlNodeList xmlnl = xn.ChildNodes;
foreach (XmlNode xmln in xmlnl)
{
if (xmln.Name == "username")
{
if (xmln.InnerText == username)
{
CurrentUser = username;
}
}
if (xmln.Name == "password")
{
if (xmln.InnerText == pwd)
{
CurrentPwd = pwd;
}
}
}
if ((CurrentUser != "") & (CurrentPwd != ""))
{
LoginStatus = true;
}
}
if (LoginStatus == true)
{
Session["UserAuthentication"] = username;
Session.Timeout = 1;
Response.Redirect("Default2.aspx");
}
else
{
Session["UserAuthentication"] = "";
}
} 
}


这篇关于在数据库中保存XML数据时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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