Re: Problems with HTTP_REFERER



All it's saying is that there is no value for the HTTP_Referer item, that
means that the array item will be a null value. It's throwing an error
because you cannot convert a null value into an uppercase string, or any
string for that matter.

You have to first check and see if it's null before you attempt to access it

if(Request.ServerVariables["HTTP_REFERER"] != null)
{
// then you can do something
}

If you have to count on the referer information don't, you don't always
receive information so a lot of the times you'll simply have a null value
here.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage


"Paperback Writer" <newsgroupms@xxxxxxxxx> wrote in message
news:u$XH1VKjFHA.1148@xxxxxxxxxxxxxxxxxxxxxxx
> Hi, I have the following code in my ASPX:
> private string pagina =
> System.IO.Path.GetFileName(System.Web.HttpContext.Current.Request.ServerVariables["HTTP_REFERER"].ToUpper());
>
> The problem is it: When i call this page directly i get an error:
>
>
> Object reference not set to an instance of an object.
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information
> about the error and where it originated in the code.
>
> Exception Details: System.NullReferenceException: Object reference not set
> to an instance of an object.
>
>
>
> I really need that, but i do not know how to accomplish this. Does someone
> can help me ?
>
>


.



Relevant Pages

  • Re: Server Error: Object reference not set
    ... "SAL" <SAL@discYou are using uploadFile control to access your uploaded ... Object reference not set to an instance of an object. ... public void Upload_click ... Line 32: string test = uploadFile.PostedFile.FileName; ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Server Error: Object reference not set
    ... "SAL" <SAL@discYou are using uploadFile control to access your uploaded ... Object reference not set to an instance of an object. ... public void Upload_click ... Line 32: string test = uploadFile.PostedFile.FileName; ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Server Error: Object reference not set
    ... You are using uploadFile control to access your uploaded file, ... Object reference not set to an instance of an object. ... public void Upload_click ... Line 32: string test = uploadFile.PostedFile.FileName; ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: [ASP.Net2] Object reference not set to an instance of an object.
    ... Object reference not set to an instance of an object. ... virtualPath, Type requiredBaseType, HttpContext context, Boolean ... String requestType, VirtualPath virtualPath, String physicalPath) +31 ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: History of programming
    ... Oriented Language (COBOL). ... 01 objCKCharset OBJECT REFERENCE COM. ... There is also a string component available from the same outfit: ... If you have solved that and it now shows correct Cyrillic characters, ...
    (comp.lang.cobol)