redirect+query string
Response.Redirect("./Backoffice.aspx?+query string);
redirect+deary
Response.AddHeader("REFRESH", "5;URL=../");
redirect normal
Response.Redirect("./Backoffice.aspx");
วันศุกร์ที่ 21 กุมภาพันธ์ พ.ศ. 2557
วันพฤหัสบดีที่ 20 กุมภาพันธ์ พ.ศ. 2557
ดึงข้อมูลจากฐานข้อมมูลแสดงบน button
Button1.Text = CStr(dt.Rows(0).Item(1).ToString)
Button2.Text = CStr(dt.Rows(1).Item(1).ToString)
Button3.Text = CStr(dt.Rows(2).Item(1).ToString)
Button4.Text = CStr(dt.Rows(3).Item(1).ToString)
cr.by greatfriends
Encode decode Url
step 1.
using System.Security.Cryptography;
using System.IO;
step 2.
create class
public class EncryptDecryptQueryString
{
private byte[] key = { };
private byte[] IV = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef };
public string Decrypt(string stringToDecrypt, string sEncryptionKey)
{
byte[] inputByteArray = new byte[stringToDecrypt.Length + 1];
try
{
key = System.Text.Encoding.UTF8.GetBytes(sEncryptionKey);
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Convert.FromBase64String(stringToDecrypt);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms,
des.CreateDecryptor(key, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
System.Text.Encoding encoding = System.Text.Encoding.UTF8;
return encoding.GetString(ms.ToArray());
}
catch (Exception e)
{
return e.Message;
}
}
public string Encrypt(string stringToEncrypt, string SEncryptionKey)
{
try
{
key = System.Text.Encoding.UTF8.GetBytes(SEncryptionKey);
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = Encoding.UTF8.GetBytes(stringToEncrypt);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms,
des.CreateEncryptor(key, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
catch (Exception e)
{
return e.Message;
}
}
}
step 3.
Page 1
if (HttpContext.Current != null)
{
string strURLWithData = "Backoffice.aspx?" + EncryptQueryString(string.Format("Typeuser={0}", strtype));
HttpContext.Current.Response.Redirect(strURLWithData);
}
else
{
}
public string EncryptQueryString(string strQueryString)
{
EncryptDecryptQueryString objEDQueryString = new EncryptDecryptQueryString();
return objEDQueryString.Encrypt(strQueryString, "r0b1nr0y");
}
step 4.
Page 2.
if (!IsPostBack)
{
string strReq = "";
strReq = Request.RawUrl;
strReq = strReq.Substring(strReq.IndexOf('?') + 1);
if (!strReq.Equals(""))
{
strReq = DecryptQueryString(strReq);
//Parse the value... this is done is very raw format..
//you can add loops or so to get the values out of the query string...
string[] arrMsgs = strReq.Split('&');
string[] arrIndMsg;
string strtype = "";
arrIndMsg = arrMsgs[0].Split('='); //Get the Name
strtype = arrIndMsg[1].ToString().Trim();
if (strtype == "Admin")
{
Label1.Visible = true;
}
else if (strtype == "User")
{
Label1.Visible = false;
}
}
else
{
Response.Redirect("Page1.aspx");
}
end
using System.Security.Cryptography;
using System.IO;
step 2.
create class
public class EncryptDecryptQueryString
{
private byte[] key = { };
private byte[] IV = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef };
public string Decrypt(string stringToDecrypt, string sEncryptionKey)
{
byte[] inputByteArray = new byte[stringToDecrypt.Length + 1];
try
{
key = System.Text.Encoding.UTF8.GetBytes(sEncryptionKey);
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Convert.FromBase64String(stringToDecrypt);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms,
des.CreateDecryptor(key, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
System.Text.Encoding encoding = System.Text.Encoding.UTF8;
return encoding.GetString(ms.ToArray());
}
catch (Exception e)
{
return e.Message;
}
}
public string Encrypt(string stringToEncrypt, string SEncryptionKey)
{
try
{
key = System.Text.Encoding.UTF8.GetBytes(SEncryptionKey);
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = Encoding.UTF8.GetBytes(stringToEncrypt);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms,
des.CreateEncryptor(key, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
catch (Exception e)
{
return e.Message;
}
}
}
step 3.
Page 1
if (HttpContext.Current != null)
{
string strURLWithData = "Backoffice.aspx?" + EncryptQueryString(string.Format("Typeuser={0}", strtype));
HttpContext.Current.Response.Redirect(strURLWithData);
}
else
{
}
public string EncryptQueryString(string strQueryString)
{
EncryptDecryptQueryString objEDQueryString = new EncryptDecryptQueryString();
return objEDQueryString.Encrypt(strQueryString, "r0b1nr0y");
}
step 4.
Page 2.
if (!IsPostBack)
{
string strReq = "";
strReq = Request.RawUrl;
strReq = strReq.Substring(strReq.IndexOf('?') + 1);
if (!strReq.Equals(""))
{
strReq = DecryptQueryString(strReq);
//Parse the value... this is done is very raw format..
//you can add loops or so to get the values out of the query string...
string[] arrMsgs = strReq.Split('&');
string[] arrIndMsg;
string strtype = "";
arrIndMsg = arrMsgs[0].Split('='); //Get the Name
strtype = arrIndMsg[1].ToString().Trim();
if (strtype == "Admin")
{
Label1.Visible = true;
}
else if (strtype == "User")
{
Label1.Visible = false;
}
}
else
{
Response.Redirect("Page1.aspx");
}
end
สมัครสมาชิก:
บทความ (Atom)