[C#.NET] QueryString问题 [英] [C#.NET] Problem with QueryString

查看:70
本文介绍了[C#.NET] QueryString问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

pagina.aspx

pagina.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="pagina3.aspx.cs" Inherits="pagina3" %>

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 <html xmlns="http://www.w3.org/1999/xhtml" >
 <head id="Head1"  runat="server">
 <title>HttpUtility Example</title>
 </head>
 <body>
 <form id="form1"  runat="server">
 <div>
 The raw url is: <br />
 <asp:Label id="UrlRawOutput"
 runat="server" />
 <br /><br />
 The url encoded is: <br />
 <asp:Label id="UrlEncodedOutput"
 runat="server" />
 <br /><br />
 The url decoded is: <br />
 <asp:Label id="UrlDecodedOutput"
 runat="server" />
 <br /><br />
 The query string NameValueCollection is: <br />
 <asp:Label id="ParseOutput"
 runat="server" />
 </div>
 </form>
 </body>
 </html>


pagina.aspx.cs


pagina.aspx.cs

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

 public partial class pagina3 : System.Web.UI.Page
 {
 protected void Page_Load(object sender, EventArgs e)
 {
 String currurl = HttpContext.Current.Request.RawUrl;
 String querystring = null;

 // Check to make sure some query string variables
 // exist and if not add some and redirect.
 int iqs = currurl.IndexOf(''?'');
 if (iqs == -1)
 {
 String redirecturl = currurl + "?email=mAKq7tfZb9zufXHN5TyPMAxNgQhaTjbtPiidyqdXSBA=&valor=XOCf2J+PiAVo5SBiYbly2w==";
 Response.Redirect(redirecturl, true);
 }
 // If query string variables exist, put them in
 // a string.
 else if (iqs >= 0)
 {
 querystring = (iqs < currurl.Length - 1) ? currurl.Substring(iqs + 1) : String.Empty;
 }

 // Parse the query string variables into a NameValueCollection.
 NameValueCollection qscoll = HttpUtility.ParseQueryString(querystring);

 // Iterate through the collection.
 StringBuilder sb = new StringBuilder();
 foreach (String s in qscoll.AllKeys)
 {
 sb.Append(s + " - " + qscoll[s] + "<br />");
 }

 // Write the results to the appropriate labels.
 ParseOutput.Text = sb.ToString();
 UrlRawOutput.Text = currurl;
 UrlEncodedOutput.Text = HttpUtility.UrlEncode(currurl);
 UrlDecodedOutput.Text = HttpUtility.UrlDecode(currurl);

 }
 }



sealguémpuder me ajudar.
如果有人可以帮助我. [Google翻译]

[edit]只是葡萄牙语到英语-OriginalGriff [/edit]



se alguém puder me ajudar.
if someone can help me. [Google Translate]

[edit]Just the Portuguese to English - OriginalGriff[/edit]

推荐答案

您的问题不太清楚.虽然听起来您在使用Querystring时遇到问题.

有关如何传递和使用查询字符串的详细信息,请参见此处:
使用QueryString在页面之间传递变量 [另一个描述该链接的链接 [
Your question is not too clear. Though it sounds like you have issues with using Querystring.

For details of how to pass and use query strings, look here:
Passing variables between pages using QueryString[^]
Another link describing the same[^]


这篇关于[C#.NET] QueryString问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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