asp.net URL生成 [英] asp.net url generation

查看:72
本文介绍了asp.net URL生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 使用系统;
使用System.Collections.Generic;
使用System.Linq的;
使用的System.Web;
使用System.Web.UI程序;
使用System.Web.UI.WebControls;
使用System.Data.SqlClient的;
使用System.Configuration;
使用System.Text;
使用System.Web.Services;
使用System.IO;命名空间T_Smade
{    公共部分类ConferenceManagement:System.Web.UI.Page
    {
        挥发性INT I = 0;        保护无效的Page_Load(对象发件人,EventArgs的发送)
        {
            GetSessionList();
        }
        公共无效GetSessionList()
        {
            字符串secondResult =;
            字符串username =;            尝试
            {
                如果(HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    USERNAME = HttpContext.Current.User.Identity.Name;
                }                SqlConnection的thisConnection =新的SqlConnection(@数据源= ZOLA-PC; AttachDbFilename = D:\\ 2 \\ 5.Devp \\我的DB \\ ASPNETDB.MDF;集成安全性=真);
                thisConnection.Open();                的SqlCommand secondCommand = thisConnection.CreateCommand();
                secondCommand.CommandText =SELECT myApp_Session.session_id FROM myApp_Session,myApp_Role_in_Session那里myApp_Role_in_Session.user_name ='+使用者名称+'和myApp_Role_in_Session.session_id = myApp_Session.session_id;
                SqlDataReader的secondReader = secondCommand.ExecuteReader();                而(secondReader.Read())
                {
                    secondResult = secondResult + secondReader [SESSION_ID]的ToString()+;;
                }
                secondReader.Close();                的SqlCommand thisCommand = thisConnection.CreateCommand();
                thisCommand.CommandText =SELECT * FROM myApp_Session;;
                SqlDataReader的thisReader = thisCommand.ExecuteReader();                而(thisReader.Read())
                {
                    test.Controls.Add(。GetLabel(thisReader [SESSION_ID]的ToString(),thisReader [会话名称]的ToString()));
                    字符串[] =比较secondResult.Split(';');
                    的foreach(在比较两个字符串字)
                    {
                        如果(字== thisReader [SESSION_ID]。的ToString())
                        {
                            test.Controls.Add(GetButton(thisReader [SESSION_ID]的ToString(),参加会议)。);
                        }
                    }
                }
                thisReader.Close();
                thisConnection.Close();            }
            赶上(SQLEXCEPTION EX)
            {            }
        }        私人按钮GetButton(字符串ID,字符串名称)
        {
            按钮B =新按钮();
            b.Text =名称;
            b.ID =Button_+身份证+我;
            b.Command + =新CommandEventHandler(Button_Click);
            b.CommandArgument = ID;
            我++;
            返回b;
        }        私人标签GetLabel(字符串ID,字符串名称)
        {
            标签TB =新的Label();
            tb.Text =名称;
            tb.ID = ID;
            返回TB;
        }        保护无效Button_Click(对象发件人,CommandEventArgs E)
        {
            的Response.Redirect(?EnterSession.aspx会话=+ e.CommandArgument.ToString());
        }
    }

当用户从该页面下一页作为

产生点击

www.mypage / Entersession.aspx?会话= SESSION_ID

但我宁愿把它像

www.mypage / Entersession.aspx?会话=会话名称

都SESSION_ID和会话名称是从数据库

什么想法?

 }


解决方案

只要修改

  test.Controls.Add(GetButton(thisReader [SESSION_ID]的ToString(),参加会议)。);

  test.Controls.Add(GetButton(thisReader [会话名称]的ToString(),参加会议)。);

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Text;
using System.Web.Services;
using System.IO;

namespace T_Smade
{

    public partial class ConferenceManagement : System.Web.UI.Page
    {
        volatile int i = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            GetSessionList();
        }


        public void GetSessionList()
        {
            string secondResult = "";
            string userName = "";

            try
            {
                if (HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    userName = HttpContext.Current.User.Identity.Name;
                }

                SqlConnection thisConnection = new SqlConnection(@"data Source=ZOLA-PC;AttachDbFilename=D:\2\5.Devp\my DB\ASPNETDB.MDF;Integrated Security=True");
                thisConnection.Open();

                SqlCommand secondCommand = thisConnection.CreateCommand();
                secondCommand.CommandText = "SELECT myApp_Session.session_id FROM myApp_Session, myApp_Role_in_Session where myApp_Role_in_Session.user_name='" + userName + "' and myApp_Role_in_Session.session_id=myApp_Session.session_id";
                SqlDataReader secondReader = secondCommand.ExecuteReader();

                while (secondReader.Read())
                {
                    secondResult = secondResult + secondReader["session_id"].ToString() + ";";
                }
                secondReader.Close();

                SqlCommand thisCommand = thisConnection.CreateCommand();
                thisCommand.CommandText = "SELECT * FROM myApp_Session;";
                SqlDataReader thisReader = thisCommand.ExecuteReader();

                while (thisReader.Read())
                {
                    test.Controls.Add(GetLabel(thisReader["session_id"].ToString(), thisReader["session_name"].ToString()));
                    string[] compare = secondResult.Split(';');
                    foreach (string word in compare)
                    {
                        if (word == thisReader["session_id"].ToString())
                        {
                            test.Controls.Add(GetButton(thisReader["session_id"].ToString(), "Join Session"));
                        }
                    }
                }
                thisReader.Close();
                thisConnection.Close();

            }
            catch (SqlException ex)
            {

            }
        }

        private Button GetButton(string id, string name)
        {
            Button b = new Button();
            b.Text = name;
            b.ID = "Button_" + id + i;
            b.Command += new CommandEventHandler(Button_Click);
            b.CommandArgument = id;
            i++;
            return b;
        }

        private Label GetLabel(string id, string name)
        {
            Label tb = new Label();
            tb.Text = name;
            tb.ID = id;
            return tb;
        }

        protected void Button_Click(object sender, CommandEventArgs e)
        {
            Response.Redirect("EnterSession.aspx?session=" + e.CommandArgument.ToString());
        }
    }

when users click from this page the next page is generated as

www.mypage/Entersession.aspx?session=session_id

but i'd rather to have it like

www.mypage/Entersession.aspx?session=session_name

both session_id and session_name are from the database

any idea?

}

解决方案

Just change

test.Controls.Add(GetButton(thisReader["session_id"].ToString(), "Join Session"));

to

test.Controls.Add(GetButton(thisReader["session_name"].ToString(), "Join Session"));

这篇关于asp.net URL生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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