Link to home
Start Free TrialLog in
Avatar of LT1415
LT1415

asked on

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

Avatar of Jarrod
Jarrod
Flag of South Africa image

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

Avatar of LT1415
LT1415

ASKER



Thanks for you response. I received this error using the snippet
Compiler Error Message: BC30451: Name 'var' is not declared
Avatar of Ravi Vaddadi
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"]
Avatar of LT1415

ASKER

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);
    }
%>
ASKER CERTIFIED SOLUTION
Avatar of masterpass
masterpass
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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];