本文整理汇总了C#中System.Web.HttpRequestBase.MapPath方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRequestBase.MapPath方法的具体用法?C# HttpRequestBase.MapPath怎么用?C# HttpRequestBase.MapPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpRequestBase
的用法示例。
在下文中一共展示了HttpRequestBase.MapPath方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSecurityRole
/// <summary>
/// Gets the security role for the given parameters.
/// </summary>
/// <param name="roleName">Name of the role.</param>
/// <param name="request">The request.</param>
/// <returns>Returns the security role for the given role name, with its permissions</returns>
public static SecurityRol GetSecurityRole(string roleName, HttpRequestBase request)
{
var cacheKey = GetRoleCacheKey(roleName);
var securityRole = HttpContext.Current.Cache[cacheKey] as SecurityRol;
if (securityRole == null)
{
var strFilePath = request.MapPath("~/Security/Roles/" + roleName + ".xml");
var xdoc = new XmlDocument();
xdoc.Load(strFilePath);
if (xdoc.DocumentElement != null)
{
securityRole = new SecurityRol(roleName, xdoc.DocumentElement);
HttpContext.Current.Cache.Insert(cacheKey, securityRole, new CacheDependency(strFilePath));
}
}
return securityRole;
}
示例2: saveArticle
//.........这里部分代码省略.........
tagArticle.tagsid = tagId;
dataContext.tags_articles.InsertOnSubmit(tagArticle);
}
dataContext.articles_categories.DeleteAllOnSubmit(dataContext.articles_categories.Where(x => x.articlesid == id));
try
{
dataContext.SubmitChanges();
}
catch (Exception)
{
return false;
}
CMS_Form_Element_Select cats = (CMS_Form_Element_Select)form["categories"];
foreach (string cat in cats.getValues())
{
long catId = long.Parse(cat);
articles_category articleCategory = new articles_category();
articleCategory.date = DateTime.Now;
articleCategory.articlesid = id;
articleCategory.categoriesid = catId;
dataContext.articles_categories.InsertOnSubmit(articleCategory);
}
try
{
dataContext.SubmitChanges();
}
catch (Exception)
{
return false;
}
if (Request.Files.Count != 2)
{
CMS_Services_Message.getInstance().addError("Unexpected count of uploaded files, skipping.");
}
else
{
HttpPostedFileBase small = Request.Files[0];
if (small.ContentLength > 0 && small.ContentType == "image/jpeg")
{
string filename = id.ToString();
var path = Path.Combine(Request.MapPath("./../images"), filename + "_small.jpg");
small.SaveAs(path);
System.Drawing.Image i = System.Drawing.Image.FromFile(path);
if (i.Width != 100 || i.Height != 100)
{
CMS_Services_Message.getInstance().addError("Invalid image size - small icon should be 100x100 pixels");
FileInfo f = new FileInfo(path);
f.Delete();
}
}
else
{
CMS_Services_Message.getInstance().addError("Invalid image - small icon");
}
HttpPostedFileBase big = Request.Files[1];
if (big.ContentLength > 0 && big.ContentType == "image/jpeg")
{
string filename = id.ToString();
var path = Path.Combine(Request.MapPath("./../images"), filename + "_big.jpg");
big.SaveAs(path);
System.Drawing.Image i = System.Drawing.Image.FromFile(path);
if (i.Width != 320 || i.Height != 240)
{
CMS_Services_Message.getInstance().addError("Invalid image size - big icon should be 320x240 pixels");
FileInfo f = new FileInfo(path);
f.Delete();
}
}
else
{
CMS_Services_Message.getInstance().addError("Invalid image - big icon");
}
}
}
catch(InvalidOperationException) {
CMS_Services_Message.getInstance().addError("Article with specified ID does not exit");
return false;
}
}
return true;
}