Tag: asp.net mvc 3

如何扩展AuthorizeAttribute并检查用户的角色

我正忙着为我的动作方法MyAuthorizeAttribute编写自己的自定义属性,我仍在忙于编写代码,这里是我的部分代码: [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] public class MyAuthorizeAttribute : AuthorizeAttribute { public new Role Roles; public override void OnAuthorization(AuthorizationContext filterContext) { base.OnAuthorization(filterContext); if (Roles != 0) // Did it this way to see what the value of Roles was return; // Here I am going to get a list of user roles // I’m doing […]

如何从类库项目加载视图?

我尝试创建VirtualPathProvider并将视图设置为嵌入式资源。 class AssemblyResourceVirtualFile : VirtualFile { string path; public AssemblyResourceVirtualFile(string virtualPath) : base(virtualPath) { path = VirtualPathUtility.ToAppRelative(virtualPath); } public override System.IO.Stream Open() { string[] parts = path.Split(‘/’); string assemblyName = parts[2]; string resourceName = parts[3]; assemblyName = Path.Combine(HttpRuntime.BinDirectory, assemblyName); var assembly = Assembly.LoadFile(assemblyName); if (assembly != null) { return assembly.GetManifestResourceStream(resourceName); } return null; } } […]

ASP .NET MVC 3模型+存储过程

我是ASP MVC中的新手,我不知道如何根据我的db中的存储过程创建模型。 我已经有数据库与另一个应用程序一起工作,我的网页必须使用提到的数据库。 如果有人可以向我展示一些描述如何做到这一点的正确方法的代码,我将不胜感激。 (如果我不清楚:我需要创建使用我的数据库中的存储过程的ASP .NET模型,仅此而已) txh提前

在静态资产和基于CDN的资产之间切换以进行开发和部署的最佳方法

我正在ASP.NET MVC3中开发和应用程序。 我计划利用亚马逊Cloudfront产品作为CDN来提供静态资产。 我很好奇是否有人设计了一种简单的方法来切换用于开发的本地资产和用于部署的基于CDN的资产? 任何提示或技巧将不胜感激。

MVC3中的角色管理

我想为应用程序添加一项function,以便只有管理员才能创建用户,并且他可以向用户提供对特定页面的访问权限。 他可以创建角色并为用户提供不同的角色。 我正在使用Visual Studio 2010并在MVC3中构建此应用程序。 请给我建议。 提前致谢。

不引人注意的DateTime? 在MVC4中validation

我将MVC3解决方案升级为MVC4。 迁移后,validation程序已损坏。 如果我选择德语作为语言,我的输入日期是“20.03.2013”​​。 我在MVC4中得到validation错误,但在MVC3中没有。 如果我将格式从“20.03.2013”​​替换为“20/03/2013”​​,它适用于MVC4,但不适用于MVC3 😉 我将当前线程的UI文化设置为德语。 ResX值的输出是正确的语言, 所以我知道文化不应该有错误。 ,仅适用于网站本身。 错误消息是英文的,但该网站是德语。 我认为这意味着validation器使用了错误的UI文化。 这是我使用的代码。 [必需(ErrorMessageResourceName =“Error_DepartureDate”,ErrorMessageResourceType = typeof(Resx.Query))] 公共日期时间? DepartureDate {get; 组; } 我假设默认模型绑定器有问题,因为渲染的html看起来很好: data-lang =“de”data-mindate =“3”data-val =“true”data-val-required =“Bitte geben Sie das gewü nschte Reisedatum des Hinflugs ein。” id =“DepartureDate”name =“DepartureDate”tabindex =“3”type =“text”value =“” 我将Jscript升级到使用Visual Studio 2012(已安装SP1)模板创建新Mvc应用程序时发布的源代码。 这没有任何影响。 我有一个CultureModelBinder,它从Session中读取当前的文化,并使用一个小帮助函数设置文化。 public static void UpdateThreadCulture(CultureInfo culture) { Thread.CurrentThread.CurrentUICulture […]

Ninject在appharbor上的应用程序启动时崩溃

我在appharbor上部署的MVC 3项目中使用了Ninject。 我注意到我在启动应用程序时遇到exception,看起来像Ninject内部的东西是原因,但我找不到任何答案 – 所以请帮助我:) 将尝试在此处添加完整的例外: Server Error in ‘/’ Application. Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: […]

在ASP.NET MVC 3中缓存数据

我有一个ASP.NET MVC 3应用程序,基本上只是一组Web服务。 这些Web服务由一组Controller操作公开。 每个控制器操作都会查询我的数 因为我的数据很少改变,并且陈旧的数据不是一个问题,我想我会实现一些缓存来提高性能。 我的目标是: 永远不要缓存对用户的响应。 将数据库记录缓存最多24小时。 如果已经过了24小时,请再次点击数据库。 那有意义吗? 我知道如何防止缓存响应。 我只使用以下内容: HttpContext.Response.Cache.SetCacheability(cacheability) 但是,我不知道如何在内存中缓存我的数据库记录长达24小时。 有没有人对如何做到这一点有任何建议? 我甚至不确定在哪里看。 谢谢

ASP.NET MVC 3 WebGrid分页问题

我的数据访问层返回带有单页行数和总行数的集合。 遗憾的是,WebGrid组件不允许指定总行数或总页数(这些属性是只读的)。 以前有人不得不处理这个问题吗?

StringLengthAttribute如何工作?

在使用Entity Framework和ASP.NET MVC3validation我的模型时,我无法使用StringLengthAttribute。 我的模型基于entity framework实体,该实体具有部分类,该部分类使用MetadataType属性告诉MVC在搜索元数据时使用哪种类型。 这显示在下面的代码中: [MetadataType(typeof(PartMetadata))] public partial class Part { } class PartMetadata { [DisplayName(“Part number”)] [Required(ErrorMessage=”* Required”)] [StringLength(50, MinimumLength = 3, ErrorMessage = “* Part numbers must be between 3 and 50 character in length.”)] public string Number { get; set; } [StringLength(255, MinimumLength=3, ErrorMessage=”* Part descriptions must be between 3 and […]