IndexOf error

R

Reena

Hi,

I am getting

error: 'strServerName.IndexOf' does not exist

message. Not sure what I am doing wrong...

following is the code form .aspx page...

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

private void Page_Load(object sender, System.EventArgs e)
{
string strServerName =
Request.ServerVariables["SERVER_NAME"].ToUpper();

if (strServerName.IndexOf("LANT") <= 0) //Not Lant
//GETTING ERROR
{
if (strServerName.IndexOf("PAC") <= 0) //Not Pac
{
Response.Write ("<font size=2 face=Arial color=Red>To
access RADWeb site, please use one of the following...");
Response.Write ("<br><br>");
Response.Write ("<A
href='http://pac.com'>https://pac.com</a>");
Response.Write ("<br><br> OR <br><br>");
Response.Write ("<A
href='http://lant.com'>https://lant.com</a>");
Response.Write ("</font>");
Response.End();
}
}
}


Help in this matter is greatly appreciated.

Thanks,

- Reena
 
A

Alvin Bruney

Reena,
it is fundamentally important that you test for null before using variables.
you aren't doing this.
if you try to find indexof on a null object it will bomb
do this
if(strServerName != null && then your index of code next
 
R

Reena

Thanks. Does not work.

Not getting any error while I am running the code. But if I step through the
code, watch window - value field displays 'strServerName.IndexOf' does not
exists.

Even if value is hardcode, strServerName = 'LANT', same error.

Thanks,

- Reena

Alvin Bruney said:
Reena,
it is fundamentally important that you test for null before using variables.
you aren't doing this.
if you try to find indexof on a null object it will bomb
do this
if(strServerName != null && then your index of code next
Reena said:
Hi,

I am getting

error: 'strServerName.IndexOf' does not exist

message. Not sure what I am doing wrong...

following is the code form .aspx page...

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

private void Page_Load(object sender, System.EventArgs e)
{
string strServerName =
Request.ServerVariables["SERVER_NAME"].ToUpper();

if (strServerName.IndexOf("LANT") <= 0) //Not Lant
//GETTING ERROR
{
if (strServerName.IndexOf("PAC") <= 0) //Not Pac
{
Response.Write ("<font size=2 face=Arial color=Red>To
access RADWeb site, please use one of the following...");
Response.Write ("<br><br>");
Response.Write ("<A
href='http://pac.com'>https://pac.com</a>");
Response.Write ("<br><br> OR <br><br>");
Response.Write ("<A
href='http://lant.com'>https://lant.com</a>");
Response.Write ("</font>");
Response.End();
}
}
}


Help in this matter is greatly appreciated.

Thanks,

- Reena
 
A

Alvin Bruney

I'm lost on this one
Reena said:
Thanks. Does not work.

Not getting any error while I am running the code. But if I step through the
code, watch window - value field displays 'strServerName.IndexOf' does not
exists.

Even if value is hardcode, strServerName = 'LANT', same error.

Thanks,

- Reena

Alvin Bruney said:
Reena,
it is fundamentally important that you test for null before using variables.
you aren't doing this.
if you try to find indexof on a null object it will bomb
do this
if(strServerName != null && then your index of code next
Reena said:
Hi,

I am getting

error: 'strServerName.IndexOf' does not exist

message. Not sure what I am doing wrong...

following is the code form .aspx page...

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

private void Page_Load(object sender, System.EventArgs e)
{
string strServerName =
Request.ServerVariables["SERVER_NAME"].ToUpper();

if (strServerName.IndexOf("LANT") <= 0) //Not Lant
//GETTING ERROR
{
if (strServerName.IndexOf("PAC") <= 0) //Not Pac
{
Response.Write ("<font size=2 face=Arial color=Red>To
access RADWeb site, please use one of the following...");
Response.Write ("<br><br>");
Response.Write ("<A
href='http://pac.com'>https://pac.com</a>");
Response.Write ("<br><br> OR <br><br>");
Response.Write ("<A
href='http://lant.com'>https://lant.com</a>");
Response.Write ("</font>");
Response.End();
}
}
}


Help in this matter is greatly appreciated.

Thanks,

- Reena
 
J

JLaw

Hello,

Just had a similar problem.

Seems like IndexOf wants to return to an int variable,

so in your example, using:

int intReturn = strServerName.IndexOf("LANT");
if (intReturn <= 0)

should do the trick.
 
L

lavey

u can tried the following code

string str_ServerName=Request.ServerVariables["SERVER_NAME"].ToUpper();
if((null!=str_ServerName) && (str_ServerName.IndexOf("LANT") > -1 )
{
// true statement
}
else
{
// false statement
}

cheerio,
Nigil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top