Wednesday, 6 June 2012

Raw ActionLink linkText

 public static IHtmlString MyActionLink(
this HtmlHelper htmlHelper,
string linkText,
string action,
string controller,
object routeValues,
object htmlAttributes
)
{
var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
var anchor = new TagBuilder("a");
anchor.InnerHtml = linkText;
anchor.Attributes["href"] = urlHelper.Action(action, controller, routeValues);
anchor.MergeAttributes(new RouteValueDictionary(htmlAttributes));
return MvcHtmlString.Create(anchor.ToString());
}




http://stackoverflow.com/questions/6063467/raw-actionlink-linktext

Friday, 1 June 2012

Adding Custom HTTP Headers to an ASP.NET MVC Response

http://blog.gregbrant.com/post/Adding-Custom-HTTP-Headers-to-an-ASPNET-MVC-Response.aspx

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
filters.Add(new HttpHeaderAttribute("X-UA-Compatible", "IE=Edge,chrome=1"));
}



or



in web.config



<system.webServer>



<httpProtocol>


  <customHeaders>




    <add name="X-UA-Compatible" value="IE=Edge,chrome=1" />


    <remove name="X-Powered-By" />




  </customHeaders>


</httpProtocol>




</system.webServer>

Saturday, 19 May 2012

Get Querystring Parameter

 public virtual T GetQueryString<T>(string name)
{
string queryParam = null;
if (Request.QueryString[name] != null)
queryParam = Request.QueryString[name];

if (!String.IsNullOrEmpty(queryParam))
return (T)TypeDescriptor.GetConverter(queryParam.GetType()).ConvertFrom(null, Thread.CurrentThread.CurrentCulture, queryParam);

return default(T);
}

Wednesday, 16 May 2012

Read a property from Active Directory

public static string GetUserProperty(string user, string propertyName)
        {
            using (var context = new PrincipalContext(ContextType.Domain, “yourDomainName”)
            {
                UserPrincipal userPrincipal = new UserPrincipal(context);
                userPrincipal.SamAccountName = user;

                PrincipalSearcher principalSearcher = new PrincipalSearcher();
                principalSearcher.QueryFilter = userPrincipal;

                Principal searchResults = principalSearcher.FindOne();

                if (searchResults != null)
                {
                    return searchResults.GetProperty(propertyName);
                }
            }

            return string.Empty;
        }

Monday, 14 May 2012

Dynamic Proxy Tutorial

http://kozmic.pl/dynamic-proxy-tutorial/

ASP.NET MVC 3 Aspect Oriented Programming with Castle Interceptors

http://cangencer.wordpress.com/2011/06/02/asp-net-mvc-3-aspect-oriented-programming-with-castle-interceptors/
http://blog.andreloker.de/post/2009/02/20/Simple-AOP-integrating-interceptors-into-Windsor.aspx

Turn off enclosing tags in CKEditor

ckeditor/config.js


CKEDITOR.editorConfig = function( config )
{
config.enterMode = CKEDITOR.ENTER_BR;
config.shiftEnterMode = CKEDITOR.ENTER_BR;
};