Tuesday, 3 October 2017

QueryString-error-The name request does not exist in the current context

After a long time, I was working on .net project. Basically I forget all basic things and on of them was how to use Query String. So here is blog for those who face issue same as me when user querystring and get error :

The name request does not exist in the current context

Below was code I was using:

if (!String.IsNullOrWhiteSpace(Convert.ToString(Request.QueryString["Source"])))
                {
                    Context.Response.Redirect(Convert.ToString(Request.QueryString["Source"]));
                }


Solution:

Solution is very easy. First, you need to add below reference in your code:

using System.Web;

This will allow you to use "HttpContext.Current" in your code. So your final solution should look like below:

if (HttpContext.Current != null && !String.IsNullOrWhiteSpace(Convert.ToString(HttpContext.Current.Request.QueryString["Source"])))
                {
                    Context.Response.Redirect(Convert.ToString(HttpContext.Current.Request.QueryString["Source"]));
                }

1 comment:

SharePoint Classic Site Retirement: Your Plan to Avoid Last-Minute Chaos

Classic SharePoint has been on borrowed time for years. Microsoft has now put dates on the remaining pieces. Microsoft will disable creation...