In the context of ASP.MVC, a view can usually be used in different routes and hence loading resources(javascripts/images etc) using relative path may not work.
For example, a view index.aspx can be used in
http://localhost/myweb/r1
http://localhost/myweb/
http://localhost/myweb/r1/subr1
And assume the resource is located in the root http://localhost/myweb/, IMHO there is no easy way to refer to the resources… trouble trouble…
That is why I have my little routine as an extension method of HtmlHelper
public static string ResolveResource(this HtmlHelper html,string url)
{
return html.ViewContext.RequestContext.HttpContext.Request.ApplicationPath + "/" + url;
}
To use it, just do these in your view:
<script src="<%=Html.ResolveResource("/Content/media/js/jquery-1.3.2.min.js") %>" type="text/javascript"></script>
December 24th, 2009
leozc
I am not sure why there are so many WRONG post about setting auto login, but here the correct one.
I tested this one in RTM windows 7.
1. Use Win+R and put in "netplwiz".
2. In the user account window, uncheck the box as below:
That is it.
Diplomatic incident —This is a true story from the Japanese Embassy in U.S.A. !!!
A few days ago, Prime Minister Mori was given some Basic English conversation training before he visits Washington and meets president Barack Obama… The instructor told Mori Prime Minister, when you shake hand with President Obama, please say “how r u”. Then Mr. Obama should say, “I am fine, and you?”
…Now you should say “me too”.. Afterwards we, translators, will do the work for you.”
It looks quite simple, but the truth is…
When Mori met Obama , he mistakenly said “who r u?” (Instead of “How r u?”.)
Mr. Obama was a bit shocked but still managed to react with humor:
“Well, I’m Michelle’s husband, ha-ha…”
Then Mori replied “me too, ha-ha.. .”.
Then there was a long silence in the meeting
Are you wondering why your ASP app is always slower than what you think?
It is a must read, like as follow here.
Want to mix MVC+Service+Entities framework+Linq+ Dynamic data in your project?
Here is the read.
Are you those people like me occasionally need try-and-error in order to figure a relative complicated LINQ statement?
Are you those people like me love to have a interactive LINQ shell to evaluate ideas quick ? Then here you go!
LINQPad lets you interactively query SQL databases in a modern query language:LINQ. Kiss goodbye to SQL Management Studio!
LINQPad supports everything in C# 3.0 and Framework 3.5:
- LINQ to SQL
- LINQ to Objects
- LINQ to XML
For basic features it is free, and it only costs $7 bucks to get the Auto-completion, which is a must have IMHO. And the best part is you can even run code snippet in the editor!

Nice table views

I happen to come across the need to export file system hirachy into an XML form for further processing, and here is my LINQ statements that does the job. Please note the recursion usage in XDirectoryElement function. Last word you need to ensure you have permission to read the directories, which doesn’t worry me in my case.
Main Function:
private static XElement XDirectoryElement(String root, String filespec)
{
return /// Create "Directory" element with Path attribute
new XElement("Directory", new XAttribute("Path", root),
new XElement("Files", /// Add "Files" sub-element
from file in Directory.GetFiles(root, filespec)orderby file
select new XElement("File", Path.GetFileName(file))),
new XElement("Subdirectories", /// Add "Subdirectories" sub-element
from dir in Directory.GetDirectories(root) orderby dir
select XDirectoryElement(dir, filespec))); /// Do it recursively!
}
The usage of the function:
String root = @"C:\Program Files\Microsoft Games";
root = Path.Combine(root, @"");
XElement xde = XDirectoryElement(root, "*.*");
String filename = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "SubDir.xml");
xde.Save(filename);
Process.Start(filename); /// Open explorer to view the file.
A trimmed down version of the Output:
< ?xml version="1.0" encoding="utf-8"?>
<directory Path="C:\Program Files\Microsoft Games">
<files />
<subdirectories>
<directory Path="C:\Program Files\Microsoft Games\Chess">
<files>
<file>Chess.dll</file>
<file>Chess.exe</file>
<file>ChessMCE.lnk</file>
<file>ChessMCE.png</file>
<file>desktop.ini</file>
</files>
<subdirectories>
<directory Path="C:\Program Files\Microsoft Games\Chess\en-US">
<files>
<file>Chess.exe.mui</file>
</files>
<subdirectories />
</directory>
</subdirectories>
</directory>
</subdirectories>
</directory>