When can Request.Url be null?

Mohayemin picture Mohayemin · Aug 27, 2012 · Viewed 7k times · Source

In my controller code I am using: Request.Url.<Something>. ReSharper suggests that Request.Url can be null.

So, when exactly can Request.Url be null? I am not talking about testing, I am interested only about an Application that is live / has already been deployed.

Please note that I have not received any NullReferenceExceptions from using Request.Url up to this point.

Answer

karaxuna picture karaxuna · Aug 27, 2012

HttpRequestBase is a class and ReSharper sees it as an actual Class, nothing more (theoretically, it can be null). So it does not analyze the usage of this specific Class.

In reality, I think that Request.Url will never be null, so just ignore ReSharper in this case.