• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1374
  • Last Modified:

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

0
LT1415
Asked:
LT1415
1 Solution
 
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now