Sunday, April 15, 2012

Calling ASP.Net Page methods using jquery???

A dummy page method :


[WebMethod()]
public static string sayHello()
{
return "hello ";
  

Please note that page methods must be declared as static, meaning a page method is completely self-contained, and no page controls are accessible through the page method.

Calling a page method from jQuery:

<script type="text/javascript">
$(document).ready(function() {
$.ajax({
type: "POST",
url: "pagemethod.aspx/sayHello",
contentType: "application/json; charset=utf-8",
data: "{}",
dataType: "json",
success: AjaxSucceeded,
error: AjaxFailed
});
});
function AjaxSucceeded(result) {
alert(result.d);
}
function AjaxFailed(result) {
alert(result.status + ' ' + result.statusText);
</script>   

Mange Form authentication and authorization using web config file??

Following code demonstrate the way it can be implement.
<authentication mode="Forms">
<forms loginUrl="login page url" timeout="30"></forms>
</authentication>


Then you should show the location which need to be restricted from anonymous users.
After the <system.web/> tag we can write following code to above purpose. It's pretty cool, isn't it..?

<location path="FolderNameAuthenticationNeed" allowOverride="true"> <system.web>
<authorization> <deny users="?"/>
</authorization> </system.web> </location>