Question: This is my code that is written in a class in a sub-folder of a main directory:

```
string c = global.RandomCode(32) + "." + ext;
using (FileStream fs = new FileStream(HttpContext.Current.Server.MapPath(@"..\adimgs\"+c),FileMode.CreateNew,FileAccess.Write))
{
    byte[] a = Convert.FromBase64String(img);
    fs.Write(a, 0, a.Length);
}

```

this works great in localhost but not in server side. as I use jquery and a page with lots of posted data calls the function in this class I don't see an error to identify the problem.

I wrote a code that saves HttpContext.Current.Server.MapPath(@"..\adimgs\"+c) in the database and the result was as expected. there must be something wrong with filestream (that works in localhost), some access authorization problem may be. Can anyone tell me what is the problem with this code?

Answer: 
From [MSDN](http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.read.aspx):

> 
> Return Value  
> 
>  Type: System.Boolean  
> 
> **true** if there are more rows; otherwise **false**.
> 
> 
> 

Now, if your command returns more than one row then values other than expected might be set. That's something to be aware of. 

From your comments it looks like you might be trying to read session variable before it was set.

Also it is very possible that value `Doctors` has slipped into database with white-space character(s) (`\r`, `\n`, `\r\n`, `space`) which are often not visible in database tools like SQL Server management studio. To check if that's the case you might use something like this:

```
if(Session["AliasUsuario"] != null)
{
    if (Session["AliasUsuario"].ToString().ToLower().Contains("doctors"))
    {
        // that's the case
    }
}

```

Also try checking what's the value of `Session["AliasUsuario"]` right after a `while` loop. A simple breakpoint could do the trick.
If `SqlDataReader r = comando.ExecuteReader();` does not return any rows you set nothing to session and therefore you cannot read anything  

I would go with something like:

```
if (r.HasRows)
{
    while(r.Read())
    {
        Session["UsuarioId"] = r["id_cliente"].ToString();
        Session["AreaUsuario"] = r["area"].ToString();
        Session["AliasUsuario"] = r["alias"].ToString();
        checkUser();
    }   
}
else
{
        Session["UsuarioId"] = "none";
        Session["AreaUsuario"] = "none";
        Session["AliasUsuario"] = "none";
}

```