本文整理汇总了C#中HttpRequest.MapPath方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRequest.MapPath方法的具体用法?C# HttpRequest.MapPath怎么用?C# HttpRequest.MapPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpRequest
的用法示例。
在下文中一共展示了HttpRequest.MapPath方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
//一些HttpRequest的属性和方法
_request = HttpContext.Current.Request;
ApplicationPath = _request.ApplicationPath;
AppRelativeCurrentExecutionFilePath = _request.AppRelativeCurrentExecutionFilePath;
Browser = _request.Browser;
FilePath = _request.FilePath;
Path = _request.Path;
Url = _request.Url;
MachinePath = _request.MapPath(Path);
//关于QueryString,Form属性的类型都是NameValueCollection
//它这个集合类型有一个特点:允许在一个键下存储多个字符串值
string[] allkeys = Request.QueryString.AllKeys;
if (allkeys.Length == 0)
Response.Redirect(
Request.RawUrl + "?aa=1&bb=2&cc=3&aa=" + HttpUtility.UrlEncode("5"), true);
StringBuilder sb = new StringBuilder();
foreach (string key in allkeys)
sb.AppendFormat("{0} = {1}<br />",
HttpUtility.HtmlEncode(key), HttpUtility.HtmlEncode(Request.QueryString[key]));
labResult.Text = sb.ToString();
}
示例2: ProcessImage
private void ProcessImage(HttpApplication app, HttpResponse Response, HttpRequest Request)
{
string file = Request.Path.Substring(4).ToLower(); // stripping out the /cms part ...
string output = "";
Response.Clear();
Response.ContentType = GetContentTypeOfFile(file);
int newWidth = 0;
int newHeight = 0;
int maxWidth = 0;
int maxHeight = 0;
if (Request["w"] != null)
newWidth = Convert.ToInt32(Request["w"].ToString());
if (Request["h"] != null)
newHeight = Convert.ToInt32(Request["h"].ToString());
if (Request["mw"] != null)
maxWidth = Convert.ToInt32(Request["mw"].ToString());
if (Request["mh"] != null)
maxHeight = Convert.ToInt32(Request["mh"].ToString());
try
{
if (newWidth > 0 || newHeight > 0 || maxHeight > 0 || maxWidth > 0)
{
// resize and render the image
// should cache it and reuse when possibl...
Image i = Image.FromFile(Request.MapPath(Request.Path));
using (MemoryStream ms = new MemoryStream())
{
int newWidth2 = newWidth;
int newHeight2 = newHeight;
if (newWidth > 0 && newHeight == 0)
newHeight2 = Convert.ToInt32(((double)i.Height / (double)i.Width) * (double)newWidth);
else if (newHeight > 0 && newWidth == 0)
newWidth2 = Convert.ToInt32(((double)i.Width / (double)i.Height) * (double)newHeight);
if (newHeight2 == 0) newHeight2 = i.Height;
if (newWidth2 == 0) newWidth2 = i.Width;
if (maxWidth > 0 && newWidth2 > maxWidth)
{
newWidth2 = maxWidth;
newHeight2 = Convert.ToInt32(((double)i.Height / (double)i.Width) * (double)newWidth2);
}
if (maxHeight > 0 && newHeight2 > maxHeight)
{
newHeight2 = maxHeight;
newWidth2 = Convert.ToInt32(((double)i.Width / (double)i.Height) * (double)newHeight2);
}
Bitmap i2 = new Bitmap(i, newWidth2, newHeight2);
i2.Save(ms, GetImageFormatOfFile(file));
Response.BinaryWrite(ms.ToArray());
}
}
else
{
// is there a way to call default handler instead of this??
Response.WriteFile(Request.MapPath(Request.Path));
}
}
catch
{
Response.WriteFile(Request.MapPath(Request.Path));
}
Response.End();
}
示例3: MapPath
static string MapPath (HttpRequest req, string virtualPath)
{
if (req != null)
return req.MapPath (virtualPath);
string appRoot = HttpRuntime.AppDomainAppVirtualPath;
if (!String.IsNullOrEmpty (appRoot) && virtualPath.StartsWith (appRoot, StringComparison.Ordinal)) {
if (String.Compare (virtualPath, appRoot, StringComparison.Ordinal) == 0)
return HttpRuntime.AppDomainAppPath;
return UrlUtils.Combine (HttpRuntime.AppDomainAppPath, virtualPath.Substring (appRoot.Length));
}
return null;
}