Monthly Archives: September 2007

ASP.NET and Retrieving Different Sections of the Current URL using Request.Url

While working on a project in ASP.NET, I needed a function that would retrieve the domain of the current url, however, I also wanted the function to also retrieve the correct ASP.NET development web server path when developing in Visual Studio. After consulting Google, I ran into this old post on Rick Strahl’s blog about the Request.Url object.

After some experimenting, I created a web page in ASP.NET 2.0 that showed what parts of the URL could be returned using different calls. Consult the following in the page load event.

    protected void Page_Load(object sender, EventArgs e)
{
Response.Write("Request.Url.AbsolutePath= " + Request.Url.AbsoluteUri);
Response.Write("<br>");
Response.Write("Request.Url.AbsoluteUri= " + Request.Url.AbsoluteUri);
Response.Write("<br>");
Response.Write("Request.Url.GetLeftPart(UriPartial.Authority)= " + Request.Url.GetLeftPart(UriPartial.Authority));
Response.Write("<br>");
Response.Write("Request.Url.GetLeftPart(UriPartial.Path)= " + Request.Url.GetLeftPart(UriPartial.Path));
Response.Write("<br>");
Response.Write("Request.Url.GetLeftPart(UriPartial.Scheme)= " + Request.Url.GetLeftPart(UriPartial.Scheme));
Response.Write("<br>");
Response.Write("Request.RawUrl= " + Request.RawUrl);
Response.Write("<br>");
Response.Write("Request.Path= " + Request.Path);
Response.Write("<br>");
Response.Write("Request.ApplicationPath= " + Request.ApplicationPath);
Response.Write("<br>");
Response.Write("Request.ResolveUrl= " + ResolveUrl("~/dealer/default.aspx"));
Response.Write("<br>");
Response.Write("GetAuthorityApplicationPath= " + GetAuthorityApplicationPath());
}

private String GetAuthorityApplicationPath()
{
return String.Concat(Request.Url.GetLeftPart(UriPartial.Authority), Request.ApplicationPath);
}

The function GetAuthorityApplicationPath() is what I needed in the end to dynamically retrieve either the domain in a production environment or the development web server url while running Visual Studio (eg. ‘http://localhost:1234/WebDirectory’)

Developing on a Open Source Platform

Lately I’ve been tasked with writing an Administration interface that’s very client heavy for a web application. It uses the Extjs framework and its widgets for building the GUI, Django + Python for the application tier, and PostgreSQL for the database end. We’re using Apache and Ubuntu Server as our platform. The entire application stack is open source, so the acquisition costs for starting development is nil.

In the past few weeks, I’ve developed more insights into the advantages of developing on a completely open source stack. The newest pro I’ve discovered is the documentation and active communities in the larger and popular projects. I know a lot of MS developers moan about the lack of adequate support available on some open source projects, but it’s not true of all them out there. When choosing components for your system, it’s almost a given that strong community support is a requirement. Fortunately in OSS projects, the utility of a project and the general following behind it go hand in hand.

I can recommend with confidence that the community support behind our application stack (Extjs, Django, Python, PostgreSQL) for our system is strong and adequate for any web application projects that you may want to pursue