LT1415
asked on
Response.Redirect if Session if Empty
I have been trying to add a redirect script on this simple line of code but it either fails or I get an error.
We are passing login information through querystring.
This code sits in every page. It works to pass the token to a meta tag if they login.
<%
string userName = Request.QueryString["UserN ame"];
if(userName != "")
{
Session["UserName"] = userName;
}
%>
What I would like to do is if username or session is empty Response.Redirect to login.
This produces a new line in constant error
<%
string userName = Request.QueryString["UserN ame"];
if(userName != "")
{
Session["UserName"] = userName;
if Session["UserName] = ""
Response.Redirect("http://blah.com/login.asp");
}
%>
Object reference not set to an instance of an object. Doesn't like (userName.Length == 0)
<%
string userName = Request.QueryString["UserN ame"];
if(userName != "")
{
Session["UserName"] = userName;
if (userName.Length == 0)
Response.Redirect("/login. asp?" + Request.Url.ToString());
}
%>
How can I get this to redirect if session is empty and they have skipped the login?
Thanks
We are passing login information through querystring.
This code sits in every page. It works to pass the token to a meta tag if they login.
<%
string userName = Request.QueryString["UserN
if(userName != "")
{
Session["UserName"] = userName;
}
%>
What I would like to do is if username or session is empty Response.Redirect to login.
This produces a new line in constant error
<%
string userName = Request.QueryString["UserN
if(userName != "")
{
Session["UserName"] = userName;
if Session["UserName] = ""
Response.Redirect("http://blah.com/login.asp");
}
%>
Object reference not set to an instance of an object. Doesn't like (userName.Length == 0)
<%
string userName = Request.QueryString["UserN
if(userName != "")
{
Session["UserName"] = userName;
if (userName.Length == 0)
Response.Redirect("/login.
}
%>
How can I get this to redirect if session is empty and they have skipped the login?
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
As they are coming in in snippets--perhaps I am not applying them correctly, but these suggestions did not resolve the problem
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks.
Thiis is what finally worked found helpful suggestions in both replies
<%
string userName = Request.QueryString["UserN ame"];
if(userName != "")
{
Session["UserName"] = userName;
}
{
Session["UserName"] = userName;
if (String.IsNullOrEmpty(user Name) == true)
Response.Redirect("/login. asp?" + Request.Url.ToString(), false);
}
%>
Thiis is what finally worked found helpful suggestions in both replies
<%
string userName = Request.QueryString["UserN
if(userName != "")
{
Session["UserName"] = userName;
}
{
Session["UserName"] = userName;
if (String.IsNullOrEmpty(user
Response.Redirect("/login.
}
%>
second first check it for null
if (Request.QueryString["User
{
string mysession= Request.QueryString["UserN
}