Error : Microsoft.VisualStudio.Web.BrowserLink.InspectModeExtensionFactory : Error JavaScript runtime error: Object doesn't support property or method
Solution: Uncheck the "Enable Browser Link" like below
![]() |
| Enable Browser Link |
Solution for the QlikView, Biztalk, DotNet and MSBI real time development problems
![]() |
| Enable Browser Link |
This How To shows how you can help protect your ASP.NET applications from cross-site scripting attacks by using proper input validation techniques and by encoding the output. It also describes a number of other protection mechanisms that you can use in addition to these two main countermeasures.
Cross-site scripting (XSS) attacks exploit vulnerabilities in Web page validation by injecting client-side script code. Common vulnerabilities that make your Web applications susceptible to cross-site scripting attacks include failing to properly validate input, failing to encode output, and trusting the data retrieved from a shared database. To protect your application against cross-site scripting attacks, assume that all input is malicious. Constrain and validate all input. Encode all output that could, potentially, include HTML characters. This includes data read from files and databases.
<system.web><pages buffer="true" validateRequest="true" /></system.web>
You can disable request validation on a page-by-page basis. Check that your pages do not disable this feature unless necessary. For example, you may need to disable this feature for a page if it contains a free-format, rich-text entry field designed to accept a range of HTML characters as input. For more information about how to safely handle this type of page, see Step 5. Evaluate Countermeasures.
<%@ Page Language="C#" ValidateRequest="false" %>
<html>
<script runat="server">
void btnSubmit_Click(Object sender, EventArgs e)
{
// If ValidateRequest is false, then 'hello' is displayed
// If ValidateRequest is true, then ASP.NET returns an exception
Response.Write(txtString.Text);
}
</script>
<body>
<form id="form1" runat="server">
<asp:TextBox id="txtString" runat="server"
Text="<script>alert('hello');</script>" />
<asp:Button id="btnSubmit" runat="server"
OnClick="btnSubmit_Click"
Text="Submit" />
</form>
</body>
</html>
A potentially dangerous Request.Form value was detected from the client (txtString="<script>alert('hello...").
This indicates that ASP.NET request validation is active and has rejected the input because it includes potentially dangerous HTML characters. Note Do not rely on ASP.NET request validation. Treat it as an extra precautionary measure in addition to your own input validation.
Response.Write <% =Search your pages to locate where HTML and URL output is returned to the client.
Response.Write(name.Text); Response.Write(Request.Form["name"]); Query Strings Response.Write(Request.QueryString["name"]);
Response.Write(Request.QueryString["username"]);
SqlDataReader reader = cmd.ExecuteReader(); Response.Write(reader.GetString(1));Be particularly careful with data read from a database if it is shared by other applications.
Response.Write( Request.Cookies["name"].Values["name"]);
Response.Write(Session["name"]); Response.Write(Application["name"]);
<%@ Page Language="C#" AutoEventWireup="true"%>
<html>
<form id="form1" runat="server">
<div>
Color: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="Show color"
OnClick="Button1_Click" /><br />
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
</div>
</form>
</html>
<script runat="server">
private void Page_Load(Object Src, EventArgs e)
{
protected void Button1_Click(object sender, EventArgs e)
{
Literal1.Text = @"<span style=""color:"
+ Server.HtmlEncode(TextBox1.Text)
+ @""">Color example</span>";
}
}
</Script>
<img src="javascript:alert('hello');">
<img src="java
script:alert('hello');">
<img src="java
script:alert('hello');">
An attacker can also use the <style> tag to inject a script by changing the MIME type as shown in the following.<style TYPE="text/javascript">
alert('hello');
</style>
Response.Write(HttpUtility.HtmlEncode(Request.Form["name"]));Do not substitute encoding output for checking that input is well-formed and correct. Use it as an additional security precaution.
Response.Write(HttpUtility.UrlEncode(urlString));
<%@ Page Language="C#" ValidateRequest="false"%>
<script runat="server">
void submitBtn_Click(object sender, EventArgs e)
{
// Encode the string input
StringBuilder sb = new StringBuilder(
HttpUtility.HtmlEncode(htmlInputTxt.Text));
// Selectively allow <b> and <i>
sb.Replace("<b>", "<b>");
sb.Replace("</b>", "");
sb.Replace("<i>", "<i>");
sb.Replace("</i>", "");
Response.Write(sb.ToString());
}
</script>
<html>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="htmlInputTxt" Runat="server"
TextMode="MultiLine" Width="318px"
Height="168px"></asp:TextBox>
<asp:Button ID="submitBtn" Runat="server"
Text="Submit" OnClick="submitBtn_Click" />
</div>
</form>
</body>
</html>
<meta http-equiv="Content Type" content="text/html; charset=ISO-8859-1" /> OR <% @ Page ResponseEncoding="iso-8859-1" %>To set the character encoding in the Web.config file, use the following configuration.
<configuration>
<system.web>
<globalization
requestEncoding="iso-8859-1"
responseEncoding="iso-8859-1"/>
</system.web>
</configuration>
using System.Text.RegularExpressions;
. . .
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// Name must contain between 1 and 40 alphanumeric characters
// and (optionally) special characters such as apostrophes
// for names such as O'Dell
if (!Regex.IsMatch(Request.Form["name"],
@"^[\p{L}\p{Zs}\p{Lu}\p{Ll}\']{1,40}$"))
throw new ArgumentException("Invalid name parameter");
// Use individual regular expressions to validate other parameters
. . .
}
}
The following explains the regular expression shown in the preceding code: | Characters | Decimal | Hexadecimal | HTML Character Set | Unicode |
|---|---|---|---|---|
| " (double quotation marks) | " | " | " | \u0022 |
| ' (single quotation mark) | ' | ' | ' | \u0027 |
| & (ampersand) | & | & | & | \u0026 |
| < (less than) | < | < | < | \u003c |
| > (greater than) | > | > | > | \u003e |
Note Web browsers that do not support the HttpOnly cookie attribute either ignore the cookie or ignore the attribute, which means that it is still subject to cross-site scripting attacks.The System.Net.Cookie class in Microsoft .NET Framework version 2.0 supports an HttpOnly property. The HttpOnly property is always set to true by Forms authentication.
protected void Application_EndRequest(Object sender, EventArgs e)
{
string authCookie = FormsAuthentication.FormsCookieName;
foreach (string sCookie in Response.Cookies)
{
// Just set the HttpOnly attribute on the Forms
// authentication cookie. Skip this check to set the attribute
// on all cookies in the collection
if (sCookie.Equals(authCookie))
{
// Force HttpOnly to be added to the cookie header
Response.Cookies[sCookie].Path += ";HttpOnly";
}
}
}
<frame security="restricted" src="http://www.somesite.com/somepage.htm"></frame>
<%@ Page Language="C#" AutoEventWireup="true"%>
<html>
<body>
<span id="Welcome1" runat="server"> </span>
<span id="Welcome2" runat="server"> </span>
</body>
</html>
<script runat="server">
private void Page_Load(Object Src, EventArgs e)
{
// Using InnerText renders the content safe–no need to HtmlEncode
Welcome1.InnerText = "Hello, " + User.Identity.Name;
// Using InnerHtml requires the use of HtmlEncode to make it safe
Welcome2.InnerHtml = "Hello, " +
Server.HtmlEncode(User.Identity.Name);
}
</Script>
var ArrivalDtValue = "15/02/2011"; // ArrivalDate}
var DepartureDtValue = "16/02/2011"; // DepartureDate
var currentTime = new Date();
var month = currentTime.getMonth();
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var currentDt = day + "/" + month + "/" + year;
var ArrDt = getDateObject(ArrivalDtValue, "/");
var DeparDt = getDateObject(DepartureDtValue, "/");
var CurDt = new Date();
//Total time for one day
var one_day = 1000 * 60 * 60 * 24;
//Here we need to split the inputed dates to convert them into standard format
//for furter execution
var x = ArrivalDtValue.split("/");
var y = DepartureDtValue.split("/");
//date format(Fullyear,month,date)
var ArrivalDate = new Date(x[2], (x[1] - 1), x[0]);
var DepartureDate = new Date(y[2], (y[1] - 1), y[0]);
var CurrentDate = new Date(year, month, day);
var month1 = x[1] - 1;
var month2 = y[1] - 1;
//Calculate difference between the two dates, and convert to days
var ArrivaldiffDays = Math.abs((CurrentDate.getTime() - ArrivalDate.getTime()) / (one_day));
var DeparturediffDays = Math.abs((CurrentDate.getTime() - DepartureDate.getTime()) / (one_day));
if (ArrDt > DeparDt) {
alert("Departure date should not be less than Arrival date");
return false;
}
else if (ArrivalDtValue == DepartureDtValue) {
alert("Arrival date and Departure date should not be same");
return false;
}
else if (ArrDt < CurrentDate)
{
alert("Arrival date should not be less than current date");
return false;
}
else if (DeparDt < CurrentDate)
{
alert("Departure date should not be less than current date");
return false;
}
else
{
return true;
}
var curValue = dateString;}
var sepChar = dateSeperator;
var curPos = 0;
var cDate, cMonth, cYear;
//extract day portion
curPos = dateString.indexOf(sepChar);
cDate = dateString.substring(0, curPos);
//extract month portion
endPos = dateString.indexOf(sepChar, curPos + 1);
cMonth = dateString.substring(curPos + 1, endPos);
//extract year portion
curPos = endPos;
endPos = curPos + 5;
cYear = curValue.substring(curPos + 1, endPos);
//Create Date Object
dtObject = new Date(cYear, cMonth - 1, cDate);
//alert(dtObject);
return dtObject;