当前位置: 首页>>代码示例>>C#>>正文


C# HttpRequestBase.MapPath方法代码示例

本文整理汇总了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;
 }
开发者ID:SolucionesAR,项目名称:SolucionesARWebsite,代码行数:23,代码来源:RolesProvider.cs

示例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;
        }
开发者ID:jirihelmich,项目名称:CMS,代码行数:101,代码来源:CMS_App_Articles.cs


注:本文中的System.Web.HttpRequestBase.MapPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。