By ParseExact
var date = System.DateTime.ParseExact(StartDate, "MM/dd/yyyy",null);
Thursday, September 27, 2012
How to check if user is logged in ASP.NET MVC
if (!Request.IsAuthenticated)
{
return RedirectToAction("LogOn","Account");
}
{
return RedirectToAction("LogOn","Account");
}
Tuesday, September 25, 2012
Large files in ASP.NET Web API
http://www.strathweb.com/2012/09/dealing-with-large-files-in-asp-net-web-api/
1. Configuring IIS
<requestLimits maxAllowedContentLength="2147483648" />
2. ASP.NET
<httpRuntime maxRequestLength="2147483648" />
3. Out of memory through buffering
public interface IHostBufferPolicySelector
{
bool UseBufferedInputStream(object hostContext);
bool UseBufferedOutputStream(HttpResponseMessage response);
}
1. Configuring IIS
<requestLimits maxAllowedContentLength="2147483648" />
2. ASP.NET
<httpRuntime maxRequestLength="2147483648" />
3. Out of memory through buffering
public interface IHostBufferPolicySelector
{
bool UseBufferedInputStream(object hostContext);
bool UseBufferedOutputStream(HttpResponseMessage response);
}
Friday, September 21, 2012
A harsh reminder about the importance of debug=”false” in ASP.NET
In debug mode, view resolution is optimized for ease of development. MVC iterates through the view resolution process each and every time your code renders a named view. That’s helpful since you obviously do want the environment to respond immediately to your changes when you’re working on a site.
In release mode, however, MVC’s view resolution is optimized for performance. When a view location is successfully resolved in release mode, MVC caches the result of that lookup and doesn’t need to perform another filesystem search when it encounters a reference to that named view again.
The result is that the apparent inefficiency of having WebForms’ naming conventions take precedence over Razor’s becomes negligible after the first resolution. So long as you don’t allow your production sites to run in debug mode, the view resolution issue is almost entirely eliminated.
debug=”false” – not just for view engines
View resolution caching is just one reason of many to ensure that you do not run your production sites in debug mode. Other serious drawbacks include:
- Timeouts – Have you ever noticed that you can spend an indefinite amount of time fooling around in the debugger without a halted request timing out? That’s because debug=”true” disables timeouts entirely, which is never a good idea on a live site.
- Bundling and Minification – ASP.NET’s new web optimization feature can automatically bundle and minify your JavaScript and CSS, but it only does so in release mode. When you run with debug=”true”, bundles are served as separate, unminified, uncombined script references with short caching headers. That’s important during development so you can read/debug your JavaScript code, but it defeats the entire point of the optimization exercise in production.
- WebResource.axd caching – Speaking of client-side resource optimization, resources served through WebResource.axd include aggressive caching headers in release mode. In debug mode, they are not cached at all.
Thursday, September 20, 2012
Wednesday, September 19, 2012
Tuesday, September 18, 2012
Monday, September 17, 2012
Thursday, September 13, 2012
Wednesday, September 12, 2012
How to set checkbox in JQuery or Javascript?
By javascript directly:
document.getElementById('checkboxID').checked = true;
document.getElementById('checkboxID').checked = false;
Problem:
In early version jQuery, the behavior in IE, FF and Chrome are different.
Or use prop function in jQuery 1.6+
document.getElementById('checkboxID').checked = true;
document.getElementById('checkboxID').checked = false;
Problem:
In early version jQuery, the behavior in IE, FF and Chrome are different.
Or use prop function in jQuery 1.6+
$(".myCheckbox").prop("checked", true);
$(".myCheckbox").prop("checked", false);
Tuesday, September 11, 2012
Monday, September 10, 2012
Thursday, September 6, 2012
How to detect and save browser language preference into cookie?
<script type="text/javascript">
$(document).ready(function () {
var c = $.cookie('userlanguage');
var userLanguage = null;
if (!c) {
var language = window.navigator.userLanguage || window.navigator.language;
$.cookie('userlanguage', userLanguage, { path: '/'});
}
});
</script>
$(document).ready(function () {
var c = $.cookie('userlanguage');
var userLanguage = null;
if (!c) {
var language = window.navigator.userLanguage || window.navigator.language;
$.cookie('userlanguage', userLanguage, { path: '/'});
}
});
</script>
Wednesday, September 5, 2012
Setting cookies with jQuery
Set a cookie
Setting a cookie with jQuery is as simple as this, where a cookie is created called "example" with a value of "foo":
1
$.cookie("example", "foo");
This is a session cookie which is set for the current path level and will be destroyed when the user exits the browser. To make the same cookie last for e.g. 7 days do this:
1
$.cookie("example", "foo", { expires: 7 });
Note: the above examples will apply the cookie to the current path level.
If the page requested is http://www.example.com/file.html then it will be set for the / path and will be available for all paths at the domain. If the page is http://www.example.com/subpath/file.html then it will be set for the /subpath level and will not be accessible at / (or /otherpath etc).
To explicitly make the cookie available for all paths on your domain, make sure the path is set:
1
$.cookie("example", "foo", { path: '/' });
To limit it to a specific path instead:
1
$.cookie("example", "foo", { path: '/admin' });
Tuesday, September 4, 2012
How to detect browsers language preference?
By Javascript:
var language = window.navigator.userLanguage || window.navigator.language;
By check request header on server side:
Request.Headers["Accept-Language"]
Accept-Language:en-US;q=0.8,en;q=0.6
var language = window.navigator.userLanguage || window.navigator.language;
By check request header on server side:
Request.Headers["Accept-Language"]
Accept-Language:en-US;q=0.8,en;q=0.6
ASP.NET MVC 4, Browser-Specific Views
private void registerDisplayMode(string agent, int index = 0)
{
DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode(agent)
{
ContextCondition = (context => context.GetOverriddenUserAgent().IndexOf
(agent, StringComparison.OrdinalIgnoreCase) >= 0)
});
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
registerDisplayMode("iPhone", 0);
registerDisplayMode("iPad", 1);
}
Subscribe to:
Posts (Atom)