asp.net C#ÍøÕ¾ÏîÄ¿ »ñÈ¡ÎïÀí·¾¶¡¢ÐéÄâ·¾¶µÄ·½·¨
-----------------------------.csÀàÎļþÖÐ
µ±Ç°ÏîÄ¿µÄÎïÀí·¾¶Â
strPath = this.Server.MapPath(Request.PhysicalApplicationPath);
ÄãҪ˵Ã÷ʲô“ÀàÎļþ”¡£ÈκÎPAGE¡¢CONTROL´úÂëÒ²ÊÇÔÚÀàÖеġ£
ÉÏÃæµÄthisÖ»Õë¶ÔPage¶ÔÏó£¬Õë¶ÔcontrolÄãÓ¦¸ÃÌæ»»Îªthis.Page¡£ÄãÒ²¿ÉÒÔʹÓãº
strPath = HttpContext.Current.Server.MapPath
(HttpContext.Current.Request.PhysicalApplicationPath);
»òÕߣ¬Ê¹Óãº
strPath = AppDomain.CurrentDomain.BaseDirectory;
--------------------------------´øpageµÄÒ³Ãæ.csÖÐ
ºÜ¾³£Ê¹Óõ½µÄÒ»¸ö¹¦ÄÜ,µ«ÔÚÔÚÍøÉÏȴһֱûÓÐÕÒµ½Ïà¹ØµÄ½â¾ö·½·¨,½ñÌì½è×ÅÏîĿӦÓõ½µÄ»ú»áдÁËÁ½
¸ö½«¾ø¶Ô·¾¶×ª»»ÎªÐéÄâ·¾¶·â×°ºÃµÄ·½·¨
¡¡¡¡½«WebÕ¾µãϵľø¶Ô·¾¶×ª»»ÎªÏà¶ÔÓÚÖ¸¶¨Ò³ÃæµÄÐéÄâ·¾¶
¡¡¡¡/**//// <summary>
¡¡¡¡/// ½«WebÕ¾µãϵľø¶Ô·¾¶×ª»»ÎªÏà¶ÔÓÚÖ¸¶¨Ò³ÃæµÄÐéÄâ·¾¶
¡¡¡¡/// </summary>
¡¡¡¡/// <param name="page">µ±Ç°Ò³ÃæÖ¸Õ룬һ°ãΪthis</param>
¡¡¡¡/// <param name="specifiedPath">¾ø¶Ô·¾¶</param>
¡¡¡¡/// <returns>ÐéÄâ·¾¶, ÐÍÈç: ../../</returns>
¡¡¡¡public static string ConvertSpecifiedPathToRelativePathForPage(Page page, string
specifiedPath)
¡¡¡¡{
¡¡¡¡ // ¸ùĿ¼ÐéÄâ·¾¶
¡¡¡¡ string virtualPath = page.Request.ApplicationPath;
¡¡¡¡ // ¸ùĿ¼¾ø¶Ô·¾¶
¡¡¡¡ string pathRooted = HostingEnvironment.MapPath(virtualPath);
¡¡¡¡ // Ò³ÃæÐéÄâ·¾¶
¡¡¡¡ string pageVirtualPath = page.Request.Path;
¡¡¡¡ if (!Path.IsPathRooted(specifiedPath) || specifiedPath.IndexOf(pathRooted) == -1)
¡¡¡¡ {
¡¡¡¡ throw new Exception(string.Format("\"{0}\"ÊÇÐéÄâ·¾¶¶ø²»ÊǾø¶Ô·¾¶!", specifiedPath));
¡¡¡¡ }
¡¡¡¡ // ת»»³ÉÏà¶Ô·¾¶
¡¡¡¡ //(²âÊÔ·¢ÏÖ£¬pathRooted ÔÚ VS2005 ×Ô´øµÄ·þÎñÆ÷¸úÔÚIISϸùĿ¼»òÕßÐéÄâĿ¼ÔËÐÐËÆºõ²»Ò
Ïà¹ØÎĵµ£º
1£ºÔÚ.aspxÒ³Ãæ£¬<% %>±êÇ©Ï൱ÓÚÔÚ.csÒ³ÃæµÄ´úÂ룬Ҳ¾ÍÊÇ˵ÄãÔÚ.csÎļþÀïÃæÔõÑùд£¬¾Í¿ÉÒÔÔÚ.aspxÎļþÀïÃæµÄ<% %>±êÇ©ÀïÃæÔõÑùд¡£
2£ºÔÚ.aspxÒ³Ãæ£¬<%= %>±êÇ©¿ÉÒÔµ÷ÓÃÄãµÄºǫ́µÄ±äÁ¿»òÕß·½·¨µÈ£¬²»¹ý±»µ÷Óõķ½·¨±ØÐëÊÇpublicµÄ¡£
Èç¹ûÄãµÄDefault.csÎļþÀïÃæÓУº
public string str = "µ÷Óúǫ́·½ ......
1.ÖØÔØprotected override bool OnBubbleEvent(object source, EventArgs args)
OnBubbleEventÊǿؼþÄÚ°üº¬µÄ¿Ø¼þÏòÍâ²ã¿Ø¼þ×÷ʼþðÅÝ
-------------------------------------------------------------------------------------------------------------------------------------------
using System;
using System.Co ......
MainPageÎļþ£ºWebForm1.aspx
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="TestMasterPage.WebForm1" enableViewState="False"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML> ......
ÔÚC#ÖÐ
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
using System.Collections.Generic;
using System.Collections;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.Ba ......