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ϸùĿ¼»òÕßÐéÄâĿ¼ÔËÐÐËƺõ²»Ò
Ïà¹ØÎĵµ£º
»ñÈ¡ÍøÕ¾¸ùĿ¼µÄ·½·¨Óм¸ÖÖÈ磺
Server.MapPath(Request.ServerVariables["PATH_INFO"])
Server.MapPath("/")
Server.MapPath("")
Server.MapPath(".")
Server.MapPath("../")
Server.MapPath("..")
&nb ......
·µ»Ø°´Å¥µÄʵÏÖ·½·¨£¨asp.net ÖУ©
Òý×Ô:http://blog.sina.com.cn/s/blog_49df2d0b0100aqoy.html
·µ»ØÉÏÒ»Ò³µÄÕâ¸ö¶«¶«ÔÚÎÒÃÇ×öÏîÄ¿µÄʱºòÒ»°ãÊÇÓÃÓÚÌîдÍê±íµ¥ºóÈ·ÈϵÄʱºò£¬ÓжÔÔÀ´ÊäÈëµÄÊý¾Ý½øÐÐÐÞ¸ÄʱÓõģ¬»òÕßÊÇÒòΪÍøվΪÁË·½±ãä¯ÀÀÕ߶øÓÐÐÄÌí¼Ó µÄÒ»¸ö¶«¶«£¬Ò»°ãÕâÖÖ¹¦ÄܵÄʵÏÖÔÚASP.netÖж¼ÊÇÓÃÒ»¸öbuttonµÄ¿ ......
ÔÚ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 ......
Ò»¡¢ÈÏʶWeb.configÎļþ
Web.config ÎļþÊÇÒ»¸öXMLÎı¾Îļþ£¬ËüÓÃÀ´´¢´æ ASP.NET Web Ó¦ÓóÌÐòµÄÅäÖÃÐÅÏ¢£¨Èç×î³£ÓõÄÉèÖÃASP.NET Web Ó¦ÓóÌÐòµÄÉí·ÝÑéÖ¤·½Ê½£©£¬Ëü¿ÉÒÔ³öÏÖÔÚÓ¦ÓóÌÐòµÄÿһ¸öĿ¼ÖС£µ±Äãͨ¹ý.NETн¨Ò»¸öWebÓ¦ÓóÌÐòºó£¬Ä¬ÈÏÇé¿öÏ»áÔÚ¸ùĿ¼×Ô¶¯´´½¨Ò»¸öĬÈ쵀 Web.configÎļþ£¬°üÀ¨Ä¬ÈϵÄÅäÖÃÉèÖ㬠......