ajax °²È«ÐÔ
ÍêÈ«ÊÊÓÃASP.NETµÄÈÏÖ¤»úÖÆ
–¿ÉÒÔʹÓÃFormsAuthentication
•WebService·½·¨¿ÉÒÔ²Ù×÷Cookie
–Impersonation
–PrincipalPermission
WebService7.cs Code
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
/// <summary>
/// WebService7 µÄժҪ˵Ã÷
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class WebService7 : System.Web.Services.WebService {
public WebService7 () {
//Èç¹ûʹÓÃÉè¼ÆµÄ×é¼þ£¬ÇëÈ¡Ïû×¢ÊÍÒÔÏÂÐÐ
//InitializeComponent();
}
[WebMethod]
public string HelloWorld() {
if (!HttpContext.Current.User.Identity.IsAuthenticated)
{
throw new ApplicationException("please Login In");
}
return "Hello "+HttpContext.Current.User.Identity.Name;
}
}
Default8.aspx Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default8.aspx.cs" Inherits="Default8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ÎÞ±êÌâÒ³</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat=server ID="aaa" ScriptMode=Debug>
<Services>
<asp:ServiceReference Path="WebService7.asmx" />
</Services>
</asp:ScriptManager>
<mce:script language=javascript type="text/javascript"><!--
function GetMessage()
{
WebService7.HelloWorld(getresult);
}
function getresult(result)
{
alert(result);
}
// --></mce:script>
<input id="Button1" type="button" value="button" on
Ïà¹ØÎĵµ£º
load(url[,data][,callback])------------->ͨ³£ÓÃÀ´´ÓWEB·þÎñÆ÷ÉÏ»ñÈ¡¾²Ì¬µÄÊý¾ÝÎļþ
url: stringÀàÐÍ ÇëÇóHTMLÒ³ÃæµÄURLµØÖ·
data(¿ÉÑ¡): object ·¢ËÍÖÁ·þÎñÆ÷µÄkey/valueÊý¾Ý
callback(¿ÉÑ¡):function ÇëÇóÍê³Éʱ»Øµ÷º¯Êý
Àý×Ó£º
Ö÷Ò³Ãæ´úÂ룺
<style type="text/css">
* { margin:0; padding ......
ajaxÈ«³ÆAsynchronous JavaScript and Xml ,Òì²½´«Êä¡£
Òì²½´«ÊäÊÇÃæÏò×Ö·ûµÄ´«Ê䣬ËüµÄµ¥Î»ÊÇ×Ö·û£»¶øÍ¬²½´«ÊäÊÇÃæÏò±ÈÌØµÄ´«Ê䣬ËüµÄµ¥Î»ÊÇÖ¡£¬Ëü´«ÊäµÄʱºòÒªÇó½ÓÊÜ·½ºÍ·¢ËÍ·¢µÄʼÖÕ±£³ÖÒ»Öµġ£
Òì²½´«ÊäÊǽ«±ÈÌØ·Ö³ÉС×éÀ´½øÐд«Êä¡£Ò»°ãÿ¸öС×éµÄÒ»¸ö8λ×Ö·û£¬ÔÚÿ¸öС×éµÄ ......
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<titl ......
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
/// <summary>
/// Summary description for Commen ......
ʵʱÊý¾ÝÑéÖ¤ÊÇAJAX¼¼ÊõµÄÒ»´óÓÅÊÆÖ®Ò»¡£Í¨¹ýÓ¦Óô˼¼Êõ£¬strutsÑéÖ¤¿ò¼Ü½«ÔöÇ¿struts MVC£¬²¢Ê¹WebÓ¦ÓóÌÐò¸ü½Ó½üÓÚ×ÀÃæÓ¦ÓóÌÐò¡£
´ËÑéÖ¤¿ò¼ÜÓÃÓÚÑéÖ¤×ֶΡ£ÓÐÐí¶àÔÚWebÓ¦ÓóÌÐòÉϽøÐÐÑéÖ¤µÄ·½·¨¡£ÕâЩ·½·¨¿É·ÖΪÁ½Àࣺ·þÎñÆ÷¶Ë·½·¨ºÍ¿Í»§¶Ë·½·¨¡£StrutsÑéÖ¤¿ò¼ÜÊÇÃæÏò»ùÓÚJavaµÄWebÓ¦Óû·¾³µÄ×î¼Ñ¿ò¼ÜÖ®Ò»¡£ËüÄܹ»ÅäÖÃÓ ......