您的位置:首页 > 其它

AWVS漏洞测试-02节-添加一个简单的新闻系统

2016-11-22 09:04 417 查看

实现一个简单的新闻发布系统

有登录 注册 添加新闻 浏览新闻 评论新闻 新闻列表 这些基本功能

使用asp.net webform

首先是登录页



protected void Button1_Click(object sender, EventArgs e)
{
string name = this.TextBox1.Text.Trim();
string pwd = this.TextBox2.Text.Trim();
if (name=="bamn"&&pwd=="123321")
{
Session["user"] = name;
Response.Redirect("/");
}
Response.Write("账号或者密码不正确");
Response.End();
}


上面是按钮事件,简单判断密码和账号,登录成功写入session,跳转到首页,否则输入提示

然后我们添加注册页



protected void Button1_Click(object sender, EventArgs e)
{
string name = this.TextBox1.Text.Trim();
string pwd = this.TextBox2.Text.Trim();
string pwd2 = this.TextBox3.Text.Trim();
if (name == "" || pwd == "")
{
ShowInfo("输入不正确");
}
else if (pwd != pwd2)
{
ShowInfo("两次密码一样");
}
//正常开发的话,这里面应该是添加到数据库中的
//我们这里就简单当做保存了 跳转到登录页
Response.Redirect("/");
}

private void ShowInfo(string info)
{
Response.Write(info);
Response.End();
}


然后就是发布新闻页了



protected void Button1_Click(object sender, EventArgs e)
{
//先判断输入是否正确
//我们这里由于没有数据库,所以这里就使用配置文件 序列化
string content = this.TextBox1.Text.Trim();
string title = this.TextBox2.Text.Trim();
if (content == "" || title == "")
{
ShowInfo("输入不正确");
}
News news = new News();
news.Content = content;
news.Title = title;
string guid = System.Guid.NewGuid().ToString();
news.Guid = guid;
news.Date = DateTime.Now.ToString();
string json = new JavaScriptSerializer().Serialize(news);
string path = Server.MapPath("~/") + "jsons\\" + guid + ".json" ;
File.WriteAllText(path, json);
Response.Redirect("/");
}

public class News
{
public string Date { set; get; }
public string Title { set; get; }
public string Content { set; get; }
public string Guid { get; set; }
}


我们这里是通过序列化保存成json文件,到jsons的目录下面

然后就是到首页了,首页我们现实列表

<form id="form1" runat="server">
<div>
<asp:Repeater ID="RepeaterNews" runat="server">
<ItemTemplate>
<div class="movies">
<a href="/view.aspx?guid=<%#Eval("Guid") %>"><%#Eval("Title") %></a>
<label><%#Eval("Date") %></label>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
</form>

protected void Page_Load(object sender, EventArgs e)
{
RepeaterNews.DataSource = GetNewList();
RepeaterNews.DataBind();
}

private List<News> GetNewList()
{
//获取文件列表
string[] files = Directory.GetFiles(Server.MapPath("~/") + "jsons\\");
List<News> newsList = new List<News>();
for (int i = 0; i < files.Count(); i++)
{
string content = File.ReadAllText(files[i]);
News news = new JavaScriptSerializer().Deserialize<News>(content);
newsList.Add(news);
}
return newsList;
}




下面再到详细页

<form id="form1" runat="server">
<div>
<asp:Label ID="LabelTitle" runat="server"></asp:Label><br />
<asp:Label ID="LabelContent" runat="server"></asp:Label><br />
<asp:Label ID="LabelDate" runat="server"></asp:Label><br />
</div>
</form>

protected void Page_Load(object sender, EventArgs e)
{
string guid = Request.QueryString["guid"];
string path = Server.MapPath("~/") + "jsons\\" + guid + ".json";
string json = File.ReadAllText(path);
News news = new JavaScriptSerializer().Deserialize<News>(json);
this.LabelContent.Text = news.Content;
this.LabelTitle.Text = news.Title;
this.LabelDate.Text = news.Date;
}




到现在为止,我们基本实现了一个新闻发布 列表 预览 注册 登录的简单功能

本集和AWVS没什么关系,主要是我们想通过这个程序来,测试我们的AWVS漏洞功能

希望对你有帮助,更多课程可以访问www.bamn.cn
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: