Thursday, August 23, 2012

html js

//javascript get value from get method and dispaly in html file
<script type="text/javascript">
  function getParameterByName(name) {
                name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
                var regexS = "[\\?&]" + name + "=([^&#]*)";
                var regex = new RegExp(regexS);
                var results = regex.exec(window.location.search);
                if (results == null)
                    return "";
                else return decodeURIComponent(results[1].replace(/\+/g, " "));
            }
document.write("<font color='yellow'>Total amount will be charge from you bank: $" + a+"</font>");
document.write("<input type='text' name='IDEBIT_AMOUNT' value='" + amount + "' />");
 </script>

//js get value from get method and set value to html controlfunction window.onload() {
        var amount = getParameterByName("amount");
        var orderID = getParameterByName("glvTransID");
        var merchdata = getParameterByName("data");
      
        document.getElementById("IDEBIT_AMOUNT").value = amount;
        document.getElementById("IDEBIT_INVOICE").value = orderID;
        document.getElementById("IDEBIT_MERCHDATA").value = merchdata;
}

Wednesday, August 22, 2012

pass value between pages

1.post  Server.Transfer same server
page1:
<asp:TextBox ID="id" runat="server" Text="456"  ></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
 protected void Button1_Click(object sender, EventArgs e)
 {        
            Server.Transfer("page2.aspx");
 }

 <input type='text' id='orderid' name='orderid' value='<% Response.Write(Page.Request.Form["id"]);%>' />  
<asp:ImageButton ID="ImageButton1" runat="server" PostBackUrl="~/LoadGLVisa.aspx"></asp:ImageButton>

2 aspx page by session
1st page set session
2nd page:
 <script type="text/javascript">
var x  = "<%=Session["id"].ToString()%> ";
 document.write(" <input type='text' id='orderid' name='orderid' value='"+x+"' />")*/ 
</script>

3.get data by get method  and display in html tag
<input type='hidden' id='orderid' name='orderid' value='<% Response.Write(Page.Request.QueryString["id"]);%>' />

4. hidden

page1:
  <asp:HiddenField ID="orderid" runat="server"  />
pageload: orderid.Value = "123456";
protected void Button1_Click(object sender, EventArgs e)
        {        
            Server.Transfer("test.aspx");
        }

page2:pageload
  HiddenField1.Value = Request.Form["orderid"].ToString();

 <asp:HiddenField ID="HiddenField1" runat="server" />
  <asp:ImageButton ID="ImageButton1" runat="server" PostBackUrl="~/LoadGLVisa.aspx" />

page3 load
 string orderid = Request.Form["HiddenField1"].ToString();

Friday, August 10, 2012

REG


Email
^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$

Credit card
 ^((4\d{3})|(5[1-5]\d{2})|(6011))-?\d{4}-?\d{4}-?\d{4}|3[4,7][\d\s-]{13}$

Friday, August 3, 2012

MOD 10

LUHN Algorithm in C# (Validate Credit Card)

 public static bool IsCreditCardValid(string cardNumber)
        {
            const string allowed = "0123456789";
            int i;
            StringBuilder cleanNumber = new StringBuilder();
            for (i = 0; i < cardNumber.Length; i++)
            {
                if (allowed.IndexOf(cardNumber.Substring(i, 1)) >= 0)
                    cleanNumber.Append(cardNumber.Substring(i, 1));
            }
            if (cleanNumber.Length < 13 || cleanNumber.Length > 16)
                return false;
            for (i = cleanNumber.Length + 1; i <= 16; i++)
                cleanNumber.Insert(0, "0");
            int multiplier, digit, sum, total = 0;
            string number = cleanNumber.ToString();
            for (i = 1; i <= 16; i++)
            {
                int n = i - 1;
                multiplier = 1 + (i % 2);
                digit = int.Parse(number.Substring(n, 1));
                sum = digit * multiplier;
                if (sum > 9)
                    sum -= 9;
                total += sum;
            }
            return (total % 10 == 0);
        }
http://www.notesbit.com/index.php/web-mysql/web-scripts/luhn-algorithm-in-c/

Thursday, August 2, 2012

Redirect page from http to https


1.
response.redirect(Request.ApplicationPath + "/Homepage.aspx");

2.
if(Request.ServerVariables["HTTPS"].ToLower() == "off")
{
strBaseURL = "http://";
}
else
{
strBaseURL = "https://";
}
strBaseURL = strBaseURL + Request.ServerVariables["SERVER_NAME"] + ":";
strBaseURL = strBaseURL + Request.ServerVariables["SERVER_PORT"];
strBaseURL = strBaseURL + Request.ServerVariables["URL"];

3.
1.) You could add a few lines of code to
your Global.asax file for the
Application_BeginRequest event handler. This handler would simply check the
current page request, via Request.Path.EndsWith("/PageName.aspx"), for
either of the two pages you need to be secure. Once it's determined if the
page requested needs to be secure, check Request.IsSecureConnection to see
if the request was already made via HTTPS. If not, redirect to
Request.Path.Replace("http://", "https://"). If the requested page is not
one of those two pages yet Request.IsSecureConnection returns True, then
redirect to Request.Path.Replace("https://", "http://") to undo the secure
connection.

2.) Another alternative is to create an HttpModule that you can install with
each project, or for the entire server via machine.config, that reads a
custom configuration section from your web.config file for the pages and
directories that need to be secured and any pages and directories that
should be ignored (i.e. requests that should remain in the protocal they
were requested). This class would read those pages into a searchable
collection and test for a match with the current requested page from the
BeginRequest event once again. A decision to redirect is made there.

4.
Switching Between HTTP and HTTPS Automatically: Version 2
http://www.codeproject.com/Articles/7206/Switching-Between-HTTP-and-HTTPS-Automatically-Ver

5.
if (!Request.IsLocal && !Request.IsSecureConnection)
{
string redirectUrl = Request.ApplicationPath + "/test.html?amount=" + amount;
//redirectUrl = Request.Url.ToString().Replace("http:", "https:");
redirectUrl = redirectUrl.ToString().Replace("http:", "https:");
Response.Redirect(redirectUrl);
}

6.
Global.asax
void Application_BeginRequest(object sender, EventArgs e)
{
int i = Request.Path.IndexOf("securepage.html");
//Request.Path="/index.aspx"
if (i != -1)  //is securepage.html,
{
   if (!Request.IsSecureConnection) //Request.IsSecureConnection=false  request is http  
{
         string path = string.Format("https{0}", Request.Url.AbsoluteUri.Substring(4));
         //Request.Url.AbsoluteUri="http://localhost:1234/securepage.html"
         //path="
https://localhost:1234/securepage.html"        
         Response.Redirect(path);
    }
}
else//any other page{}
}

7.
 void Application_BeginRequest(object sender, EventArgs e)
{
  if (Request.Path.EndsWith("/index.aspx"))
    {
       if (!Request.IsSecureConnection)// http
         {                   
            string securePath=Request.Url.AbsoluteUri.ToString().Replace("http://", "https://");
            //securePath=https://
            Response.Redirect(securePath);
          }
     }
     else
     {
              
      }              
}

8.
if (!Request.IsLocal && !Request.IsSecureConnection)           
{
  string s1 = Request.ApplicationPath + "index.asxp";
  // Request.ApplicationPath=”/”;
  // s1= “/index.aspx”
  string s2 = Request.Url.ToString().Replace("http:", "https:"); 
  // Request.Url=http://localhost:1234/index.aspx
  //    s2= https://localhost:1234/index.aspx  
  Response.Redirect(s1);
}

9.
string strBaseURL = "";
if (Request.ServerVariables["HTTPS"].ToLower() == "off")
{
   strBaseURL = "http://";
}
else
{
   strBaseURL = "https://";
}
strBaseURL = strBaseURL + Request.ServerVariables["SERVER_NAME"] + ":";
//https://localhost:
strBaseURL = strBaseURL + Request.ServerVariables["SERVER_PORT"];
//https://localhost:1234
strBaseURL = strBaseURL + Request.ServerVariables["URL"];
//https://localhost:1234/test.aspx
strBaseURL = strBaseURL.Replace("LoadGLVisa.aspx", "index.aspx");
//https://localhost:1234/index.aspx
Response.Redirect(strBaseURL);