Lorenz Cuno Klopfenstein

Articles from April 2010

A peculiarity of URL generation in ASP.NET MVC that often bugged me is that you cannot generate URLs outside of an ASP.NET HttpContext. All built in URL generation classes (HtmlHelper, UrlHelper, LinkBuilder etc.) will throw an exception if called without the right parameters or when HttpContext.Current is null.

ASP.NET MVC

This is only because these classes need to know the path of the ASP.NET application they are running in, in order to generate correct relative URLs. For example, a typical website URL can have this form:

http://www.example.com/path/to/application/route/page?parameter=value

In this case our ASP.NET application is hosted under the /path/to/application path. All requests to paths under that application will be forwarded to our app instance and then handled by the ASP.NET routing module. In order to generate links to another page, you can use the full absolute path:

http://www.example.com/path/to/application/route2

or a relative one:

../route2

or, as MVC always does, links that start at the root folder of the host:

/path/to/application/route2

Thus the problem lies in the fact that the host name and the application path can only be found in the current HttpRequest instance. As long as MVC continues to generate URLs in that form, we'll have to manually supply the correct application path in some way when we try to use the URL builders outside of a HttpContext (this is mostly the case when you generate e-mails on a background thread or similar scenarios).

More...

Posted on Monday, April 05, 2010
Tagged as
3155 Views
6 comments posted

In the last months there has been a silent and progressive change in my family. A slow revolution that has overruled every rational economic decision and forced us to buy Apple computers (I refuse to cite the usual “PC vs. Mac” thingie since it's just not true: Macs are overpriced PCs!).

So, after my brother bought a Mac Book Pro when he left for his school, my mother followed with another Apple laptop. Still justifiable, since both of them do computer design and after all every self-respectable designer wouldn't suit for nothing less than a Mac. But then... we inexcusably also bought a 27 inch iMac!

Unpacking our new 27' iMac.
Unpacking our new 27' iMac.

We started using it in the kitchen to watch movies most of all — a rather underutilized piece of hardware until now. Still, the screen is absolutely gorgeous and watching movies on it is a pleasure.

Anyway, I was “keeping it real” and was standing by my PC-only principles... that is, until the finishing blow struck. For the last months I have been working at some new project for the University of Urbino. The professor I'm working with went on a “we got money, we gotta spend it” buying spree (not really, but quite) and bought some new hardware for the lab I work in. One of those machines was indeed a Mac Book Pro 13, which has then been assigned to me.  :) Yuppie.
An offer I couldn't refuse of course.

More...

Posted on Friday, April 23, 2010
573 Views
3 comments posted
Back to Klopfenstein.net
Clemens Klopfenstein Serena Kiefer Lukas Tiberio Klopfenstein Lorenz Cuno Klopfenstein
English German