Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am writing this code & it show conversion error. I try it but doesn't find answer.
string requestedDomain = HttpContext.Current.Request.Url.ToString().ToLower();
           
            if ((requestedDomain.IndexOf("http://yoursite.com") + 1))

This if condition show error :  Can not implicity convert type int to bool 
Posted
Updated 9-Jul-12 23:22pm
v2

if(var)

is syntax if bool value check
you should use like this
if(var == value)
if ((requestedDomain.IndexOf("http://yoursite.com") + 1) == someintvalue)
 
Share this answer
 
Comments
Prasad_Kulkarni 13-Jul-12 0:09am    
5'ed
pradiprenushe 13-Jul-12 0:35am    
thanks
The method string.IndexOf() returns an integer. You should expand the expression to make it a boolean by comparing the result to zero.
 
Share this answer
 
v2
Comments
Mas11 10-Jul-12 5:29am    
okk.. Thanks for answer.. But i think the code is right plz check it

try {
string requestedDomain = HttpContext.Current.Request.Url.ToString().toLower();


if (Strings.InStr(requestedDomain, "http://yoursite.com")) {
requestedDomain = requestedDomain.Replace("http://yoursite.com", "http://www.yoursite.com");

Response.Clear();
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location", requestedDomain);
Response.End();

}

} catch (Exception ex) {
Response.Write("Error in Global.asax :" + ex.Message);
}
Richard MacCutchan 10-Jul-12 5:34am    
This is a totally different question, what is its problem?
Prasad_Kulkarni 13-Jul-12 0:09am    
5'ed
I think the error message is self explanatory. You are try to evaluate a int in a IF Block, and it should be a boolean.

Your code should look something like this:

C#
if ((requestedDomain.IndexOf("http://yoursite.com") + 1) > 1)
{
    // > 1 is just an example...
}
 
Share this answer
 
Comments
Prasad_Kulkarni 13-Jul-12 0:09am    
Yes A +5!
Manas Bhardwaj 13-Jul-12 3:43am    
thx!
If() block is a conditional statement and it only checks whether the value in the braces is of type boolean or not.

Since the value in your if statement is of type int it should be equated to an another integer value

int age;
age=27;
like if(age==18)
{
//do something
}
else
{
// do some thing
}
 
Share this answer
 
Hey guys its a small error. I solve it..

if ((requestedDomain.IndexOf("http://localhost:50555/website15/default.aspx") > -1))
 
Share this answer
 
Comments
pradiprenushe 10-Jul-12 6:13am    
I think in every solution everybody has tell the same thing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900