![]() |
|
|
|
#1 |
|
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 ? Paperback Writer |
|
|
|
|
#2 |
|
Posts: n/a
|
If there is no HTTP_REFERER (no page from which this page was navigated to),
the ServerVariable will be null. You need to check for this, as "ToUpper()" will throw an exception if the string is null. -- HTH, Kevin Spencer Microsoft MVP ..Net Developer The sun never sets on the Kingdom of Heaven "Paperback Writer" <> wrote in message news:u$... > 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 ? > > Kevin Spencer |
|
|
|
#3 |
|
Posts: n/a
|
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" <> wrote in message news:u$... > 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 ? > > Mark Fitzpatrick |
|
|
|
#4 |
|
Posts: n/a
|
your referer is probably an empty string if your not referred to the page
from somewhere- your trying to getfilename on an empty string hence the exception, use a try catch or check the value of referrer first -- Regards John Timney ASP.NET MVP Microsoft Regional Director "Paperback Writer" <> wrote in message news:u$... > 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 ? > > John Timney \(ASP.NET MVP\) |
|
|
|
#5 |
|
Posts: n/a
|
I can not check with clause IF because it's out of a method...it's a private
string into the class! "John Timney (ASP.NET MVP)" <> escreveu na mensagem news:e$... > your referer is probably an empty string if your not referred to the page > from somewhere- your trying to getfilename on an empty string hence the > exception, use a try catch or check the value of referrer first > > -- > Regards > > John Timney > ASP.NET MVP > Microsoft Regional Director > > "Paperback Writer" <> wrote in message > news:u$... >> 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 ? >> >> > > Paperback Writer |
|
|
|
#6 |
|
Posts: n/a
|
The fact that you can do this:
System.Web.HttpContext.Current.Request.ServerVaria bles["HTTP_REFERER"].ToUpp er()); says you DO have access to the null string in question. Richard "Paperback Writer" <> wrote in message news:%... > I can not check with clause IF because it's out of a method...it's a private > string into the class! > > "John Timney (ASP.NET MVP)" <> escreveu na mensagem > news:e$... > > your referer is probably an empty string if your not referred to the page > > from somewhere- your trying to getfilename on an empty string hence the > > exception, use a try catch or check the value of referrer first > > > > -- > > Regards > > > > John Timney > > ASP.NET MVP > > Microsoft Regional Director > > > > "Paperback Writer" <> wrote in message > > news:u$... > >> Hi, I have the following code in my ASPX: > >> private string pagina = > >> System.IO.Path.GetFileName(System.Web.HttpContext. Current.Request.ServerVari ables["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 ? > >> > >> > > > > > > Kan Coon |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Re: Pioneer DVR-105 and Nero Problems | grams@oldtown.com | DVD Video | 1 | 08-12-2003 04:17 AM |
| Re: Pioneer DVR-105 and Nero Problems | Ron | DVD Video | 1 | 08-08-2003 06:33 PM |
| Re: Pioneer DVR-105 and Nero Problems | Flossie | DVD Video | 0 | 08-07-2003 02:25 PM |
| Re: Pioneer DVR-105 and Nero Problems | Flossie | DVD Video | 0 | 08-07-2003 08:11 AM |
| Re: Pioneer DVR-105 and Nero Problems | CAM | DVD Video | 0 | 08-07-2003 02:30 AM |