Jack @ ASP.NET

As a software engineer, I focus on .NET, especially asp.net, C#, WCF and so on, and I am also very interested in Search Engine Optimization.

Entries for March, 2010

How to launch a process with admin rights from a Visual Studio 2008 add-in on Windows System with UAC.

While on Windows XP by default every user is an administrator (although you can create “standard” users) Windows Vista introduces a new feature named User Account Control (UAC) which causes that by default even administrators run as standard users. When a process requires administrator rights to run, the operating system prompts for an “elevation prompt”.

Here is a demo:

System.Diagnostics.Process process = null;
System.Diagnostics.ProcessStartInfo processStartInfo;

processStartInfo = new System.Diagnostics.ProcessStartInfo();

processStartInfo.FileName = "regedit.exe";

if (System.Environment.OSVersion.Version.Major >= 6)  // Windows Vista or higher
{
   processStartInfo.Verb = "runas";
}
else
{
   // No need to prompt to run as admin
}

processStartInfo.Arguments = "";
processStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
processStartInfo.UseShellExecute = true;

try
{
   process = System.Diagnostics.Process.Start(processStartInfo);
}
catch (Exception ex)
{
   MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
   if (process != null)
   {
      process.Dispose();
   }
}

ASP.NET MVC 2 Released

The final release of VS 2010 and Visual Web Developer 2010 will have ASP.NET MVC 2 built-in – so you won’t need an additional install in order to use ASP.NET MVC 2 with them.

ASP.NET MVC 2 Features

  • New Strongly Typed HTML Helpers
  • Enhanced Model Validation support across both server and client
  • Auto-Scaffold UI Helpers with Template Customization
  • Support for splitting up large applications into “Areas”
  • Asynchronous Controllers support that enables long running tasks in parallel
  • Support for rendering sub-sections of a page/site using Html.RenderAction
  • Lots of new helper functions, utilities, and API enhancements
  • Improved Visual Studio tooling support

ASP.NET MVC 2 is the next significant update of ASP.NET MVC. It is a compatible update to ASP.NET MVC 1 – so all the knowledge, skills, code, and extensions you already have with ASP.NET MVC continue to work and apply going forward.

ASP.NET MVC 2 is the next significant update of ASP.NET MVC. It is a compatible update to ASP.NET MVC 1 – so all the knowledge, skills, code, and extensions you already have with ASP.NET MVC continue to work and apply going forward. Like the first release, we are also shipping the source code for ASP.NET MVC 2 under an OSI-compliant open-source license.

ASP.NET MVC 2 is the next significant update of ASP.NET MVC. It is a compatible update to ASP.NET MVC 1 – so all the knowledge, skills, code, and extensions you already have with ASP.NET MVC continue to work and apply going forward. Like the first release, we are also shipping the source code for ASP.NET MVC 2 under an OSI-compliant open-source license.

Visual Stusio 2010: Quickly Closing Documents

Before (VS 2008)

image

After (VS 2010)

image

The majority of feedback around this change was positive, but, as with most UI changes, there has been a vocal group that preferred the older placement.  When asked what they liked about the old placement, 99% of the time the response was, “I liked the ability to quickly close tabs by repeatedly clicking on the ‘X’ without moving my mouse.” 

I’ll admit it: I used that feature quite a bit to quickly close tabs.  That is, until I found out that there are better and more efficient ways to clean up the Tab Well.  Once I discovered these, I never looked back.  So, for this “Tips and Tricks” article, I wanted to share some of those ways to quickly close documents. 

 

image#1: Window->Close All Documents

Under the Window menu is a handy command: Close All Documents.  Clicking this will prompt you to save your work and will then close all documents that are currently open.  Yes, this does affect more than just the documents in the Tab Well – floating documents are also closed.  If you don’t want to take your hands off the keyboard, simply press Alt+ W, L, to invoke the command (You can also assign it a keyboard shortcut under Tools->Options->Environment->Keyboard).

 #2: Ctrl+F4

Another handy shortcut is Ctrl+F4 which, on most machines, is bound to the command Window.CloseDocumentWindow.  Pressing this keyboard combination will close the current document window that has focus.  Therefore, if you want to quickly get rid of a number of items in your tab well, just keep pressing Ctrl+F4 and eventually they’ll be gone. 

#3: Right-Click->Close All But This

If you want to close all but one open file, simply right-click on the tab and select Close All But This.  This will close all open documents (floating included) except the tab you’ve right-clicked on. 

#4: Middle Click

For those that prefer to use the mouse instead of the keyboard, there’s still a quick way to close tabs: the middle click.  This shortcut actually works in a number of other applicatios as well.  Simply place your mouse on the tab well and middle click to close the tab.  You can keep your mouse in the first spot and click away.

Microsoft will Increased Support of Client Development Through the jQuery JavaScript Library

Industry standards and innovation took center stage at MIX10, as Microsoft Corp. made a series of announcements that underscore the company’s commitment to interoperability and performance on the Web. Dean Hachamovitch, general manager of Internet Explorer at Microsoft, unveiled the Internet Explorer 9 Platform Preview including expanded support for HTML5, hardware-accelerated graphics and text, and a new JavaScript engine. Together these allow developers to use the same markup and deliver graphically and functionally rich Web applications that take advantage of modern PC hardware through a modern operating system.

Microsoft also announced that it will contribute to the development of new features and enhancements in the jQuery JavaScript Library and shared the release of new software development kits (SDKs) for the Open Data Protocol (OData) that make it easier for developers to access data from the cloud to create more compelling cross-platform Web applications.

As part of Microsoft’s broad engagement with open source communities, Corporate Vice President Scott Guthrie today announced that Microsoft is investing resources to contribute to the development of the jQuery JavaScript Library to help improve the development process of standards-based Web applications. Microsoft will also work to provide better interoperability between ASP.NET and the jQuery JavaScript Library by enhancing ASP.NET so .NET developers can better incorporate jQuery capabilities. In addition, Microsoft will actively promote and distribute versions of the jQuery JavaScript Library by packaging it with popular products such as Microsoft Visual Studio 2010 and ASP.NET MVC 2. As a first step, Microsoft will contribute a templating engine to the jQuery JavaScript Library Team to simplify Web applications.

Get XmlEnumAttribute value for an Enum field in C#

Sometimes, we have to convert an Enum back to its original Xml value, after google the solution, I fond it is not hard to implement, and share it here

Method

public static string ConvertToString(Enum e)
{
// Get the Type of the enum
Type t = e.GetType();

// Get the FieldInfo for the member field with the enums name
FieldInfo info = t.GetField(e.ToString("G"));
// Check to see if the XmlEnumAttribute is defined on this field
if (!info.IsDefined(typeof(XmlEnumAttribute), false))
{
// If no XmlEnumAttribute then return the string version of the enum.
return e.ToString("G");
}
else
{
// Get the XmlEnumAttribute
object[] o = info.GetCustomAttributes(typeof(XmlEnumAttribute), false);
XmlEnumAttribute att = (XmlEnumAttribute)o[0];
return att.Name;
}
}

A demo of how to use this method

static void Main()
{
// Get the XmlEnumAttribute
Console.WriteLine(ConvertToString(TestEnumClass.Three));

Console.WriteLine(ConvertToString(TestEnumClass.Two));
}

public enum TestEnumClass
{
One = 1,
Two = 2,
[System.Xml.Serialization.XmlEnum("The Third one")]
Three = 3,
}

IIS7 FastCGI

FastCGI extension has a set of configuration settings that controls the behavior of FastCGI processes associated with the FastCGI process pool. This section lists all the settings supported by FastCGI and their format:

* ExePath – The physical path to the process executable to use in the pool
* Arguments – Arguments to pass to each process in the pool at start time. This setting is optional.
* EnvironmentVars – Environment variables that are set for the process executable associated with this pool.
Some more improvement including:
# Monitor changes to a file. The module can be configured to listen for file change notifications on a specific file and when that file changes, the module will recycle FastCGI processes for the process pool. This feature can be used to recycle PHP processes when changes to php.ini file occur. To enable this feature use the monitorChangesTo setting in the configuration element.
# Real-time tuning of MaxInstances setting. This MaxInstances setting dictates the maximum number of FastCGI processes which can be launched for each application pool. Set it to 0 to let FastCGI module automatically adjust the number of instances up or down based on the system load and number of requests waiting in the queue.
# STDERR stream handling. There are several options of how the module can handle text sent by FastCGI application on STDERR. The module can send the error data as a failure response to the HTTP client or it can ignore the error and send whatever was received on STDOUT as a response with 200 status code. This behavior is controlled by the stderrMode setting.
# Sending a termination signal to FastCGI processes. The module can be configured to send a termination signal to FastCGI process before terminating it. This enables FastCGI processes to do a clean shutdown before getting killed. The signalBeforeTerminateSeconds setting can be used to specify how long the module will wait before it forcefully shuts down the FastCGI process that does not respond to the termination signal. This feature is disabled by default.
# _FCGI_X_PIPE_ environment variable. This variable is set by FastCGI module and it contains the name of the named pipe that is used for communication between the module and FastCGI process.
# Relaxed enforcement of response headers syntax. The FastCGI module now has less strict enforcements for the correctness of the response headers.
# Using UTF-8 encoding for server variable values. By default FastCGI uses ASCII encoding when setting server variables. If a FastCGI application requires UTF-8 encoded values for certain server variables, the module can be configured to use UTF-8 only for required server variables.