How to monitor/trace Windows Network Activity

October 18th, 2010 leozc Comments off

Sometimes you really need to know what is going on under the hook of windows network stack, why DNS is not resolving, why you always get 404 etc. Windows actually provides a very powerful infrastructure to allow trace through

What you need:
1. Windows Performance Analysis Tools (google it, or here)
2. Open cmd windows under admin permission.
3. Do “netsh trace start scenario=internetclient capture=yes persistent=yes”
4. Perform the activities you want to investigate.
5. “netsh trace stop” to stop the tracing.

It will have a ETL file generated, in my example : C:\Users\myusername\AppData\Local\Temp\NetTraces\NetTrace.etl

And open this using Microsoft® Windows® Performance Analyzer, take a look and have fun!

Screenshot from ETL viewer

Screenshot from ETL viewer

Share/Save/Bookmark

Categories: Random Talk, Tech, windbg Tags:

Safely locate & load resource in ASP.MVC view

June 9th, 2010 leozc Comments off

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>

Share/Save/Bookmark

Categories: ADO.Net, C#, Tech Tags:

Windows 7 RTM Auto Login Setup

December 24th, 2009 leozc Comments off

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:

image

That is it.

Share/Save/Bookmark

Categories: Random Talk Tags:

Diplomatic incident —This is a true story from the Japanese Embassy in U.S.A. !!!

July 11th, 2009 leozc Comments off
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

Share/Save/Bookmark

Categories: Random Talk Tags:

The Secret of ASP View Data

July 1st, 2009 leozc Comments off

Are you wondering why your ASP app is always slower than what you think?

It is a must read, like as follow here.

Share/Save/Bookmark

Categories: ASP Tags:

ADO.Net Entity framework Table Per Type mapping

June 29th, 2009 leozc Comments off

Good reading from here

Share/Save/Bookmark

Categories: ADO.Net, Random Talk Tags:

A good read on hybrid ASP.Net technologies

June 26th, 2009 leozc Comments off

Want to mix MVC+Service+Entities framework+Linq+ Dynamic data in your project?

Here is the read.

Share/Save/Bookmark

Categories: Random Talk Tags:

Scott Hanselman’s 2007 Ultimate Developer and Power Users Tool List for Windows

May 18th, 2009 leozc Comments off
Categories: Random Talk Tags:

LINQPad: A Lightweight SQL Studio Replacement for LINQ Developer

March 27th, 2009 leozc Comments off

Are you those people like me occasionally need try-and-error in order to figure a relative complicated LINQ statement?linqpadlogo

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!

image

 

Nice table views :)

 

Technorati Tags:

Share/Save/Bookmark

Categories: Linq, Random Talk Tags: , ,

LINQ: Generate File System Hierarchy in XML

March 26th, 2009 leozc Comments off

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>

Share/Save/Bookmark

Categories: Linq Tags: , ,