Thursday, May 29, 2014

How to remove ASP.NET response headers Server, X-AspNet-Version, X-AspNetMvc-Version and X-Powered-By?

Need two steps:
Step 1: add following code into Global.asax
protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
        {
            HttpContext.Current.Response.Headers.Remove("X-Powered-By");
            HttpContext.Current.Response.Headers.Remove("X-AspNet-Version");
            HttpContext.Current.Response.Headers.Remove("X-AspNetMvc-Version");
            HttpContext.Current.Response.Headers.Remove("Server");
        }

AND

Step 2
Add following config into web.config file

    
      
        
        
      
    
  

Is ASP.Net vNext The New Node.js

http://blog.jaywayco.co.uk/?p=210

Monday, May 26, 2014

How to valid URL in ASP.NET MVC data annotation?


[Display("URL")]
[RegularExpression(@"^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_]*)?$", ErrorMessage = "Invalid URL")]
public string Url { get; set; }


Reference:
Website to test regular expression
http://regex101.com/

Common Regular Expressions
http://msdn.microsoft.com/en-us/library/ff650303.aspx

Wednesday, May 21, 2014

How to fix problem, MSDTC on server xxx is unavailable?

Following are the steps I did to fix the problem:
- Uninstall: msdtc -uninstall
- Install: msdtc -install
- restarting DTC service;

Do not FORGET
- Restart SQL Server service

Tuesday, May 20, 2014

Wednesday, May 7, 2014

Why need method/function overloading in C#?

Keep same naming convention. Can not find any other benefit for overloading.

Optional parameter should be the first choice to try.
Do not put different purposes thing under same name.

Friday, May 2, 2014

How to add number only validation in ASP.NET MVC data model by Data Annotation attribute?

[Range(0, int.MaxValue, ErrorMessage = "Number please")]

How to solve, 401 unauthorized issue for ASP.NET Windows authentication in Visual studio 2013

Go to folder:
Documents\IISExpress\config

Open config file and Set windowsAuthentication to true
<windowsAuthentication enabled="true">