using System.Reflection;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace me.ExtensionMethods
{
public static class Html
{
public static MvcHtmlString AbsoluteActionLink(this HtmlHelper htmlHelper, string text, string actionName, string controllerName, object routeValues, object htmlAttributes)
{
var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
string baseUrl = BaseUrl(htmlHelper.ViewContext.RequestContext.HttpContext.Request, urlHelper.Content("~/"));
var rd = CastBackTo(routeValues);
string routelist = GetRouteData(rd);
var htmls = CastBackTo(htmlAttributes);
string htmlattributeslist = GetHtmlAttributes(htmls);
var htmlstring = string.Format("{4}", baseUrl, actionName, controllerName, routelist, text, htmlattributeslist);
return new MvcHtmlString(htmlstring);
}
private static string GetHtmlAttributes(RouteValueDictionary htmls)
{
string htmlattributeslist = "";
foreach (var one in htmls.Keys)
{
object value = "";
htmls.TryGetValue(one, out value);
htmlattributeslist = htmlattributeslist + string.Format("{0}='{1}'", one, value);
}
return htmlattributeslist;
}
private static string GetRouteData(RouteValueDictionary rd)
{
string routelist = "";
foreach (var one in rd.Values)
{
routelist = routelist + (routelist == "" ? "" : "/") + one;
}
return routelist;
}
public static RouteValueDictionary CastBackTo(object ob)
{
RouteValueDictionary result = new RouteValueDictionary();
foreach (PropertyInfo property in ob.GetType().GetProperties())
{
result.Add(property.Name, property.GetValue(ob, null));
}
return result;
}
public static string BaseUrl(HttpRequestBase Request, string rootpath)
{
var baseUrl = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, rootpath);
if (!baseUrl.ToLower().Contains("localhost"))
{
string result = "";
string[] baseUrlSections = baseUrl.ToLower().Split("/".ToCharArray());
foreach (var one in baseUrlSections)
{
if (one.Contains(":") && !one.Contains("http"))
{
result = result + "/" + one.Substring(0, one.IndexOf(":"));
}
else
{
result = result + (result == "" ? "" : "/") + one;
}
}
baseUrl = result;
}
return baseUrl;
}
}
}
Wednesday, December 4, 2013
AbsoluteActionLink, an extended method for HtmlHelper to render an absolute URL in ASP.NET MVC 3
Tuesday, December 3, 2013
How to fix disappeared Immediate Windows in Visual Studio menu?
If cannot find it in View menu, then open Command Windows first by:
View -> Other Windows ->Command Window:
Then type: immed and enter.
View -> Other Windows ->Command Window:
Then type: immed and enter.
Thursday, November 28, 2013
How to solve problem: Visual Studio cannot recognize name space even already added related project as reference?
Check two projects’ target framework are same.
My case: one target framework is .Net 4.0, another is .Net 4.5
My case: one target framework is .Net 4.0, another is .Net 4.5
CSS box model and element vertical align issue
http://krugerdavid.com/journal/understanding-blueprintcss/
Many vertical align issues are related to margine and padding value, so understand css box model will be helpful.
Many vertical align issues are related to margine and padding value, so understand css box model will be helpful.
Wednesday, November 27, 2013
How to solve "This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false". "
When deploy a website on IIS Server first time, get following 500 internal server error:
This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".
The first thing to do is to run
turn on/off Windows features:
So can check if related features are enabled on the server

This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".
The first thing to do is to run
turn on/off Windows features:
So can check if related features are enabled on the server
Subscribe to:
Posts (Atom)