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...
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.
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.
steve_flynn
Member
22 Points
49 Posts
Unrecognised Code
Feb 15, 2012 08:30 AM|LINK
Hi
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">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Forms Experimentation</title>
</head>
<body>
<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>
</form>
<h2>Request Parameters</h2>
<h3>Query String Parameters</h3>
<% foreach (string key in Request.QueryString.Keys)
Response.Write(key + " = " + Request.QueryString[key] + "<br />");
%>
</body>
</html>
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.
Thanks
Steve
CollyMelon
Participant
997 Points
222 Posts
Re: Unrecognised Code
Feb 15, 2012 08:43 AM|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:
steve_flynn
Member
22 Points
49 Posts
Re: Unrecognised Code
Feb 15, 2012 09:22 AM|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.
Steve