Wednesday, February 5, 2014

How to wrap up a static html page into ASP.NET MVC Action?

Without layout, it is very easy
public ActionResult PrivacyPolicy()
        {
            //return View();
            return Content(System.IO.File.ReadAllText(Server.MapPath("~/privacypolicy.html")));
        }


With layout
In Controller
public ActionResult PrivacyPolicy()
        {
            return View();
        }
In view file
@Html.Raw(File.ReadAllText(Server.MapPath("~/privacypolicy.html")))

Tuesday, February 4, 2014

What is OR operator in CSS selector?

Comma:

h1, h2, h3 { font-family: sans-serif }

In W3 calls grouping
http://www.w3.org/TR/CSS2/selector.html#grouping

Monday, February 3, 2014

How to get visitor IP address in static method?

        protected static string GetUserIPAddress()
        {
            string VisitorsIPAddr = string.Empty;
            if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
            {
                VisitorsIPAddr = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
            }
            else if (System.Web.HttpContext.Current.Request.UserHostAddress.Length != 0)
            {
                VisitorsIPAddr = System.Web.HttpContext.Current.Request.UserHostAddress;
            }
            return VisitorsIPAddr;
        }

Thursday, January 30, 2014

How to fix problem: In ASP.NET form authentication, cookie only working under compatibility mode in IE 10 or above?

In web.config file, Add cookieless="UseCookies" property into Form Authentication section
<authentication mode="Forms">
<forms cookieless="UseCookies" loginurl="/" name=".AUTH" path="/" timeout="10000">
</forms></authentication>
Reference:
http://stackoverflow.com/questions/6983732/ie10-user-agent-causes-asp-net-to-not-send-back-set-cookie-ie10-not-setting-coo