Last post Feb 15, 2012 10:22 AM by steve_flynn
Feb 15, 2012 09:30 AM|steve_flynn|LINK
I am about to start a project which will be published to the web so I have purchased a book about asp.net security. The first chapter tells me to create a web project and create a page with the following HTML code...
<%@ Page Language="vb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<h2>Request Type = <%=request.httpmethod %></h2>
<form action="Default.aspx" method="get">
<p>Example Input : <input type="text" name="example" /></p>
<p><input type="submit" value="Submit" /></p>
<h3>Query String Parameters</h3>
<% foreach (string
key in Request.QueryString.Keys)
Response.Write(key + " = " + Request.QueryString[key] + "<br />");
I have entered the code word for word but the text highlighted in bold in underlined by Visual Studio, indicating that the code is not valid. The only difference I have is that my code says language="vb" and the book's code says language="C#". Surely this
won't make any difference for the HTML? Attempting to run the code gives the following server error...
Compiler Error Message: BC30451: 'foreach' is not declared. It may be inaccessible due to its protection level.
My understanding of HTML isn't great, if anyone could tell what's going wrong here, I would be most grateful.
Feb 15, 2012 09:43 AM|CollyMelon|LINK
It will make a difference yes - this part of your code:
<% foreach (stringkey in Request.QueryString.Keys) Response.Write(key
+ " = " + Request.QueryString[key] + "<br />"); %>
Is wrote in c# - your page language is VB.
Change the code to VB like so:
<%For Each key As String In Request.QueryString.Keys
Response.Write((key & " = ") + Request.QueryString(key) & "<br />")
Feb 15, 2012 10:22 AM|steve_flynn|LINK
Thanks for your reply, this works just fine. Unfortunately, it seems that this book will be of no use to me as I don't code in C#. Thanks again for your help.