Home » Applications » ASP.NET » Archive by category "VS2010"

Archive for the 'VS2010' Category

HTTP – HTTPS Redirect

VB code If Not Request.IsLocal AndAlso Not Request.IsSecureConnection Then Dim redirectUrl As String = Request.Url.ToString().Replace(“http:”, “https:”) Response.Redirect(redirectUrl) End If C# code if (!Request.IsLocal && !Request.IsSecureConnection) { string redirectUrl = Request.Url.ToString().Replace(“http:”, “https:”); Response.Redirect(redirectUrl); } Classic asp Read more… ‘do https stuff dim httpsStuff httpsStuff = Request.ServerVariables(“PATH_INFO”) if Request.ServerVariables(“QUERY_STRING”) “” then httpsStuff = httpsStuff & “?” & […]

Read the content of the folder – VB.NET

<%@ Page Language=”VB” %> <%@ Import Namespace=”System” %> <%@ Import Namespace=”System.IO” %> <%@ Import Namespace=”System.IO.FileInfo” %> <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”> <style type=”text/css”> ul { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal; line-height: 25px; font-variant: normal; color: #0C4F93; text-indent: 5px; list-style-position: outside; list-style-type: square; } <script runat=”server”> Protected Sub Page_Load(ByVal […]

Validate date in code behind with regex – VB.NET

Code behind ‘define public var Protected StartDate As String Protected EndDate As String ‘define other var Dim sDate = Request.Form(“startDateTbx”) Dim eDate = Request.Form(“endDateTbx”) Dim r As Regex r = New Regex(“^(0[1-9]|[1-9]|1[012])/(0[1-9]|[1-9]|[12][0-9]|3[01])/20\d\d$”) ‘run validation If sDate = “” Then startDateLbl.Text = “Required” ElseIf Not r.Match(sDate).Success Then startDateLbl.Text = “Invalid date. Use mm/dd/yyyy.” Else startDateLbl.Text = […]