内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

ASP.NET如何通過(guò)更改Url實(shí)現(xiàn)頁(yè)面?zhèn)髦?創(chuàng)新互聯(lián)

這篇文章主要講解了“ASP.NET如何通過(guò)更改Url實(shí)現(xiàn)頁(yè)面?zhèn)髦怠?,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“ASP.NET如何通過(guò)更改Url實(shí)現(xiàn)頁(yè)面?zhèn)髦怠卑桑?/p>

成都創(chuàng)新互聯(lián)公司自成立以來(lái),一直致力于為企業(yè)提供從網(wǎng)站策劃、網(wǎng)站設(shè)計(jì)、成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、電子商務(wù)、網(wǎng)站推廣、網(wǎng)站優(yōu)化到為企業(yè)提供個(gè)性化軟件開(kāi)發(fā)等基于互聯(lián)網(wǎng)的全面整合營(yíng)銷服務(wù)。公司擁有豐富的網(wǎng)站建設(shè)和互聯(lián)網(wǎng)應(yīng)用系統(tǒng)開(kāi)發(fā)管理經(jīng)驗(yàn)、成熟的應(yīng)用系統(tǒng)解決方案、優(yōu)秀的網(wǎng)站開(kāi)發(fā)工程師團(tuán)隊(duì)及專業(yè)的網(wǎng)站設(shè)計(jì)師團(tuán)隊(duì)。

這里,通過(guò)假數(shù)據(jù),手動(dòng)創(chuàng)建的一個(gè)類,然后創(chuàng)建的一個(gè)集合,放入下拉框,選好值以后,點(diǎn)確定
會(huì)在另一個(gè)頁(yè)面產(chǎn)生對(duì)應(yīng)的id

創(chuàng)建一個(gè)類:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebApplication1
{
 public class Dept
 {
  public int Id { get; set; }
  public string DeptName { get; set; }
 }
}

一個(gè)選擇的web窗體

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Dept.aspx.cs" Inherits="WebApplication1.Dept1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 <title></title>
</head>
<body>
 <form id="form1" runat="server">
  <div>
   <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true">

   </asp:DropDownList>
  </div>
  <p>><a href="dept_<%=DropDownList1.SelectedValue %>.html" rel="external nofollow" >查詢</a></p>
 </form>
</body>
</html>

選擇的web窗體的后臺(tái)代碼

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
 public partial class Dept1 : System.Web.UI.Page
 {
  protected void Page_Load(object sender, EventArgs e)
  {
   if (!IsPostBack)
   {
    LoadDeptData();
   }
  }

  private void LoadDeptData()
  {
   //手動(dòng)創(chuàng)建數(shù)據(jù)
   List<Dept> depts = new List<Dept>
   {
    new Dept{Id=1,DeptName="小明"},
    new Dept{Id=2,DeptName="小王"},
    new Dept{Id=3,DeptName="小李"}
   };
   this.DropDownList1.DataSource = depts;
   //默認(rèn)顯示的值
   this.DropDownList1.DataTextField = "DeptName";
   this.DropDownList1.DataValueField = "Id";
   //保存
   this.DropDownList1.DataBind();
  }
 }
}

建一個(gè)繼承Modules類

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;

namespace WebApplication1.Modules
{
 public class DeptModule : IHttpModule
 {
  public void Dispose()
  {

  }

  public void Init(HttpApplication context)
  {
   context.BeginRequest += Context_BeginRequest;  
  }

  private void Context_BeginRequest(object sender, EventArgs e)
  {
   //處理請(qǐng)求
   //獲取請(qǐng)求url
   HttpApplication application = sender as HttpApplication;
   //相對(duì)路徑
   string url = application.Request.RawUrl;
   //一個(gè)正則,用來(lái)匹配是不是相對(duì)應(yīng)的頁(yè)面
   Regex regex = new Regex(@"dept_(\d+).html");
   //正則的匹配后的,微軟給鋪好的路,正則匹配后的一個(gè)數(shù)組;
   GroupCollection groupCollection = regex.Match(url).Groups;
   //這里取得是數(shù)組的第一個(gè)值,看看是不是成功匹配了,
   if (groupCollection[0].Success)
   {
    //取到第二個(gè)值
    var id = groupCollection[1].Value.Trim('_');
    //存儲(chǔ)id,等用到的時(shí)候直接去第二個(gè)頁(yè)面去取值
    HttpContext.Current.RewritePath("~/DeptDetail.aspx","","deptid="+id);

   }
  }
 }
}

建完了類,要進(jìn)入配置文件進(jìn)行配置
因?yàn)槲疫@里是放在一個(gè)文件夾下面了,所以配置文件指定type的時(shí)候,要加一個(gè)文件夾的路徑

ASP.NET如何通過(guò)更改Url實(shí)現(xiàn)頁(yè)面?zhèn)髦?></p><pre> <system.webServer>
 <modules>
  <add name="Module" type="WebApplication1.Modules.DeptModule"/>
 </modules>
 </system.webServer></pre><p>顯示的web窗體</p><pre><%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DeptDetail.aspx.cs" Inherits="WebApplication1.DeptDetail" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 <title></title>
</head>
<body>
 <form id="form1" runat="server">
  <div>
   <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  </div>
 </form>
</body>
</html></pre><p>顯示的web窗體的后臺(tái)代碼</p><pre>using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
 public partial class DeptDetail : System.Web.UI.Page
 {
  protected void Page_Load(object sender, EventArgs e)
  {
   if (!IsPostBack)
   {
    //直接通過(guò)request獲取Module存入的id
    this.TextBox1.Text = $"{Request.QueryString["deptid"]}";
   }
  }
 }
}</pre><p>效果圖</p><p>選擇一個(gè)后點(diǎn)擊查詢</p><p><img src=ASP.NET如何通過(guò)更改Url實(shí)現(xiàn)頁(yè)面?zhèn)髦?創(chuàng)新互聯(lián)
URL鏈接:http://m.rwnh.cn/article36/iidpg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化自適應(yīng)網(wǎng)站、定制開(kāi)發(fā)軟件開(kāi)發(fā)、網(wǎng)站制作、靜態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

綿陽(yáng)服務(wù)器托管
广昌县| 龙里县| 紫云| 汉中市| 九龙县| 扎兰屯市| 美姑县| 海盐县| 湄潭县| 民权县| 丰都县| 阳原县| 镇平县| 资溪县| 东安县| 华蓥市| 阿克苏市| 绿春县| 嘉义市| 辽源市| 托克逊县| 公安县| 梁河县| 乐山市| 中宁县| 巴中市| 宜城市| 疏勒县| 南丹县| 康保县| 新乡县| 谢通门县| 贵州省| 仁寿县| 如皋市| 肃北| 黄浦区| 瑞金市| 仁布县| 五大连池市| 嫩江县|