Skip to main content

Posts

Showing posts from October, 2014

Jquery valiadtion

This is a pretty good link about Jquery validation: http://www.javascript-coder.com/form-validation/jquery-form-validation-guide.phtml#rules_dynamic Add a rule dynamically: $(selector).rules( 'add' ,{max:50}); Remove a rule:   $(selector).rules( 'remove' ,'max'); Create a new rule: (For example, password policy that uses regular expression for validation) 1. Inside $(document).ready(), add following line of code:         $.validator.addMethod(                 "passwordpolicy",                 function (value, element, regexp) {                     var re = new RegExp(regexp);                     return this.optional(element) || re.test(value);                 },                 "Password must contain at least one letter and one digit"         ); 2. In the HTML markup where you need to use this validation rule, add data-rule attribute data-rule-passwordpolicy and provide the regular expression as the value. The passwordpoli

Forms authentication ReturnUrl strange behavior and fix

When working with .NET forms authentication, I have found a strange behavior: For example, we have a web site using form based authentication. There are only two pages in the site: login.aspx and default.aspx. Default.aspx is the protected page. Without login to the site, if you type directly the URL to the default.aspx page with ReturnUrl as QueryString like this: http://localhost/YourWebApp/Default.aspx?ReturnUrl=Default.aspx Instead of redirect you to the login.aspx page, you will directly get http unauthorized error (401.2). However, if you remove the ReturnUrl query string or change it to something else, you will get expected behavior: redirect to login.aspx page. It seems .NET has some special treatment to ReturnUrl parameter. In order to fix this, we need to intercept the 401 response before it sends to client and redirect user to login.aspx page. In global.asax page, we need to add this event handler:         protected void Application_PreSendRequestHeaders( object