这一篇中,我实现了,登录和游客环境下,在首页中单击博文标题跳转到该篇博文,点击博文作者跳转到该作者博客首页,在我的博客中点击博文标题跳转到该篇博文。
这些跳转都是在同一个页面中实现的,我用母版页放个人博客的导航和公告。web页面放datalist实现博文的,由于不会后台调用datalist中的控件,更改不了textbox的大小,我把数据库更改了,数据库中有个单独存放博文摘要的,准备以后实现下自动选取摘要,所以我用了2个datalist来显示全博文,和详细博文,写到这我有个想法,把它换成两张表是不是可以更好的实现。
1 //MyBlogs.master 2 using System; 3 using System.Collections.Generic; 4 using System.Linq; 5 using System.Web; 6 using System.Web.UI; 7 using System.Web.UI.WebControls; 8 using System.Data; 9 using Business; 10 using Entity; 11 public partial class MyBlogs : System.Web.UI.MasterPage 12 { 13 protected void Page_Load(object sender, EventArgs e) 14 { 15 if (Session["uid"] == null) 16 { 17 18 if (Request.QueryString["uid"] == null && Request.QueryString["bid"] == null) 19 { 20 21 } 22 if(Request.QueryString["uid"] != null && Request.QueryString["bid"] == null) 23 { 24 Cind(); 25 } 26 if (Request.QueryString["uid"] == null && Request.QueryString["bid"] != null) 27 { 28 Aind(); 29 } 30 } 31 else 32 { 33 if (Request.QueryString["uid"] == null && Request.QueryString["bid"] == null) 34 { 35 Bind(); 36 } 37 if (Request.QueryString["uid"] != null && Request.QueryString["bid"] == null) 38 { 39 Cind(); 40 } 41 if (Request.QueryString["uid"] == null && Request.QueryString["bid"] != null) 42 { 43 Aind(); 44 } 45 46 } 47 } 48 public void Bind()//我的博客 49 { 50 UserBusiness uname = new UserBusiness(); 51 UserEntity user = new UserEntity(); 52 user.Uid = Session["uid"].ToString(); 53 DataTable dt = new DataTable(); 54 dt = uname.FindUserInfo(user); 55 DataList1.DataSource = dt; 56 DataList1.DataBind(); 57 DataList2.DataSource = dt; 58 DataList2.DataBind(); 59 } 60 public void Aind()//该篇博文 61 { 62 BlogsBusiness blogs = new BlogsBusiness(); 63 BlogsEntity b = new BlogsEntity(); 64 DataTable dt = new DataTable(); 65 b.Bid=Convert.ToInt32( Request.QueryString["bid"]); 66 dt = blogs.SelectUid(b); 67 DataList1.DataSource = dt; 68 DataList1.DataBind(); 69 DataList2.DataSource = dt; 70 DataList2.DataBind(); 71 72 } 73 public void Cind() 74 { 75 UserBusiness uname = new UserBusiness(); 76 UserEntity user = new UserEntity(); 77 user.Uid = Request.QueryString["uid"]; 78 DataTable dt = new DataTable(); 79 dt = uname.FindUserInfo(user); 80 DataList1.DataSource = dt; 81 DataList1.DataBind(); 82 DataList2.DataSource = dt; 83 DataList2.DataBind(); 84 } 85 86 protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e) 87 { 88 if (e.CommandName == "user") 89 { 90 Response.Redirect("UserBlogs.aspx?uid=" + e.CommandArgument.ToString()); 91 } 92 if (e.CommandName == "NewBlogs") 93 { 94 Response.Redirect("NewBlogs.aspx?uid=" + e.CommandArgument.ToString()); 95 } 96 if (e.CommandName == "Manage") 97 { 98 Response.Redirect("Manage.aspx?uid=" + e.CommandArgument.ToString()); 99 } 100 } 101 } 102 //UserBlogs.aspx 103 using System; 104 using System.Collections.Generic; 105 using System.Linq; 106 using System.Web; 107 using System.Web.UI; 108 using System.Web.UI.WebControls; 109 using System.Data; 110 using Business; 111 using Entity; 112 public partial class UserBlogs : System.Web.UI.Page 113 { 114 protected void Page_Load(object sender, EventArgs e) 115 { 116 if (Session["uid"] == null) 117 { 118 if (Request.QueryString["uid"] == null && Request.QueryString["bid"] == null) 119 { 120 121 } 122 if (Request.QueryString["uid"] != null && Request.QueryString["bid"] == null) 123 { 124 Cind(); 125 } 126 if (Request.QueryString["uid"] == null && Request.QueryString["bid"] != null) 127 { 128 Aind(); 129 } 130 } 131 else 132 { 133 134 if (Request.QueryString["uid"] == null && Request.QueryString["bid"] == null) 135 { 136 Bind(); 137 } 138 if (Request.QueryString["uid"] != null && Request.QueryString["bid"] == null) 139 { 140 Cind(); 141 } 142 if (Request.QueryString["uid"] == null && Request.QueryString["bid"] != null) 143 { 144 Aind(); 145 } 146 } 147 } 148 149 public void Aind()//该篇博文 150 { 151 BlogsBusiness blogs = new BlogsBusiness(); 152 BlogsEntity b = new BlogsEntity(); 153 DataTable dt = new DataTable(); 154 b.Bid =Convert.ToInt32(Request.QueryString["bid"]); 155 dt = blogs.SelectUid(b); 156 DataList1.DataSource = dt; 157 DataList1.DataBind(); 158 } 159 public void Bind()//我的博客 160 { 161 BlogsBusiness blogs = new BlogsBusiness(); 162 BlogsEntity b = new BlogsEntity(); 163 DataTable dt = new DataTable(); 164 b.Uid = Session["uid"].ToString(); 165 dt = blogs.SelectBid(b); 166 DataList2.DataSource = dt; 167 DataList2.DataBind(); 168 } 169 public void Cind()//他人的博客 170 { 171 BlogsBusiness blogs = new BlogsBusiness(); 172 BlogsEntity b = new BlogsEntity(); 173 DataTable dt = new DataTable(); 174 b.Uid = Request.QueryString["uid"]; 175 dt = blogs.SelectBid(b); 176 DataList2.DataSource = dt; 177 DataList2.DataBind(); 178 } 179 180 181 182 183 184 protected void DataList2_ItemCommand(object source, DataListCommandEventArgs e) 185 { 186 if (e.CommandName == "blogs") 187 { 188 Response.Redirect("UserBlogs.aspx?bid=" + e.CommandArgument.ToString()); 189 } 190 } 191 }
我通过3条if判断登录下和非登录下的情况的。
后面还用之前的方法跳转到发布和管理页面,但是这个在后台代码中要判断是否登录,没有登录的话需要登录。