BC30109: 'String' is a class type, and so is not a valid expression.

I have a small snippet of c# coding in my aspx page which is supposed to check for
a user name. There is no coding in the back end.

I am getting an error message:
on this line
string userName = Request.QueryString["UserName"];

BC30109: 'String' is a class type, and so is not a valid expression error.



<%@ Page Language="c#" Inherits="peepapers" CodeFile="peepapers.aspx.cs" %>
<%@ Register TagPrefix="pu" TagName="footer" Src="footer.ascx" %>
<!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">

<%
string userName = Request.QueryString["UserName"];
if(userName != "")
{
Session["UserName"] = userName;
}
 
{
      Session["UserName"] = userName;
 

if (String.IsNullOrEmpty(userName) == true)  

Response.Redirect("http://www.blah.com", false);
}

%>

I don't know if this makes a difference or not but,

The page is supposed to be asp.net 2.0.It is is just a simple page and not an application.
The parent directory is also asp.net 2.0

However the error from the Web page
States that the version information is 1.1.4

Thanks

LT1415Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zadeveloperCommented:
try this script.
<%
    var userName = Request.QueryString["UserName"];
    
    if(!string.IsNullOrEmpty(userName))
    {
        Session["UserName"] = userName;
    }

    if (!string.IsNullOrEmpty(Session["UserName"] as string))
    {
        Response.Redirect("http://www.blah.com", false);
    }
%>

Open in new window

0
LT1415Author Commented:


Thanks for you response. I received this error using the snippet
Compiler Error Message: BC30451: Name 'var' is not declared
0
SriVaddadiCommented:
var keyword does not work with asp.net 2.0. var is .net 3.0 feature.

Request.QueryString.GetValues("UserName")[0] instead of Request.QueryString["UserName"]
0
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

LT1415Author Commented:
Thank you SriVaddadi:
I tried using the snippet below.
I sure that the server is running aspnet 2.0 framework.


CS0246: The type or namespace name 'var' could not be found (are you
missing a using directive or an assembly reference?)


<%

    var UserName = Request.QueryString.GetValues("UserName")[0];
   
    if(!string.IsNullOrEmpty(userName))
    {
        Session["UserName"] = userName;
    }

    if (!string.IsNullOrEmpty(Session["UserName"] as string))
    {
        Response.Redirect("http://www.blah.com", false);
    }
%>
0
masterpassCommented:
What happens when you change like this
<%
    string userName = Request.QueryString["UserName"];
    
    if(!string.IsNullOrEmpty(userName))
    {
        Session["UserName"] = userName;
    }

    if (!string.IsNullOrEmpty(Session["UserName"] as string))
    {
        Response.Redirect("http://www.blah.com", false);
    }
%>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SriVaddadiCommented:
i did not mean

    var UserName = Request.QueryString.GetValues("UserName")[0];

Sorry for the confusion. This is what I wanted you to try.

string userName = Request.QueryString.GetValues("UserName")[0];
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.