Get URL of MVC Webpage
I have an ASP.Net MVC web application that will be used on a number of
different machines. I want to get the URL of the page as a string as I
then use the Url for selenium automated testing.
I have tried using the following code:
public static string getUrl()
{
Uri uri = HttpContext.Current.Request.Url;
String absoluteUrlBase =
uri.Scheme + "://" +
uri.Host +
(uri.IsDefaultPort ? "" : ":" + uri.Port);
return absoluteUrlBase;
}
But get a error 'object reference not set to an instance of an object'
using this method.
No comments:
Post a Comment