Tag: asp.net mvc 3

针对不同区域的不同认证模式

我有两个部分正在处理的网站:一个使用普通表单身份validation,另一个使用基于HMAC的身份validation。 基于表单的表单正常工作(使用自定义成员资格提供程序除外)。 最令人沮丧的是,默认情况下,如果决定使用表单身份validation,则会将所有401响应重定向到身份validation标记下的根Web.config中指定的loginUrl。 为了努力为我的网站的HMAC部分关闭此function,我创建了一个单独的区域,这些控制器存在。但是,无论我在哪里放置标签(无论是在区域/视图Web.config,我放置在区域文件夹中的Web.config,或根目录Web.config中的位置标记下(这样做实际上导致该标签不属于那里的错误))我不能似乎让这件事停止将所有401重定向到loginUrl。 任何帮助都会非常感激,因为这会让我把头发撕掉。 顺便说一句,这个问题已经被问过不同的方式至少2 次没有(可行)的反应。 虽然我的重点是将身份validation模式设置为None,但他们通常专注于更改路径的角色(在我看来,每个方法的[Authorize(Roles=”role1,role2,role3″)]属性更容易)让我的问题有点不同。 如果这是不可能的,请告诉我,以便我能找到更好的方法来做到这一点。

ASP.NET MVC 3 Generic DisplayTemplates

我刚刚使用ASP.NET MVC 3开始了一个项目。我正在现有的对象系统之上构建,所以我要做的第一件事就是为现有的各种类型定义显示和编辑器模板。 在MVC中是否可以使用generics参数定义DisplayTemplate? 例如,我们有一个BitString类,它将枚举作为generics参数,并表示包含所提供枚举的选项列表。 我希望我可以定义一个处理所有BitString实例的显示/编辑器模板。 我目前正在使用Razor作为我的观点,但我不介意混合和匹配ascx(或直接C#,如果有办法做到这一点)来实现这一点 谢谢 编辑:我认为这可能是这个问题的重复…但它已经有一年半了,所以也许有人在这一点上有更好的答案? 通用局部视图:如何将generics类设置为模型?

将rassor元素添加到razor元素中

剃刀如果我有类似的东西: @Html.EditorFor(model => model.name)或甚至: @Html.CheckBoxFor(m => m.RememberMe) 我如何向他们添加css类或id? 我一直在阅读帮助者,但我是否必须为每一个元素做一个帮手? 有没有简单的方法来添加类或id到剃刀表单元素?

Foreach Razor里面的Foreach

我正在尝试编写一个foreach循环,它将找到每个不同的类别类型,然后列出具有该类别分配的每个Title。 例如: @model IEnumerable @{ ViewBag.Title = “Home”; } @foreach (var item in Model) { @Html.DisplayFor(modelItem => item.ProgramType.ProgramType) foreach (var listing in Model) { @Html.DisplayFor(modelItem => listing.ProgramTitle) } } 调查回复模型: public class SurveyProgramModel { [Key] public int ProgramId { get; set; } public int ProgramYear { get; set; } public int ProgramStatusId { get; set; […]

使用授权属性时出现NullReferenceException

我在HomeController上有[Authorize]属性,每当我尝试访问它时,它都会抛出NullReferenceException 这真的有点奇怪,因为我以前多次使用[Authorize]并且它工作得很好。 在这种情况下,唯一的区别是此应用程序使用Windows 7和IIS 7.5托管在我们自己的Web服务器上 这是Stack Trace: [NullReferenceException:对象引用未设置为对象的实例。] System.Web.Mvc.AuthorizeAttribute.AuthorizeCore(HttpContextBase httpContext)+38 System.Web.Mvc.AuthorizeAttribute.OnAuthorization(AuthorizationContext filterContext)+160 System.Web.Mvc.ControllerActionInvoker.InvokeAuthorizationFilters(ControllerContext controllerContext,IList`1filter,ActionDescriptor actionDescriptor)+155 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext,String actionName)+784976 System.Web.Mvc.Controller.ExecuteCore()+159 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)+335 System.Web.Mvc。 c_ DisplayClassb.b _5()+62 System.Web.Mvc.Async。 c_ DisplayClass1.b _0()+ 20 System.Web.Mvc。 c_ DisplayClasse.b _d()+54 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+ 453 System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean&completedSynchronously)+371 编辑: 在查看AuthorizeCore方法的代码时,似乎AuthorizeCore抛出了NullReferenceException因为它获取了一个NULL HttpContextBase 。 有可能吗? 因为应用程序中的其他所有工作都很好,比如访问数据库,创建auth cookie等。 编辑2: 只有在将其发布到Web Server后才会发生这种情况。 在开发过程中,它在Visual Studio中运行得非常好。

Sequence包含多个匹配元素 – 使用Entiity Framework添加项目

我用谷歌搜索了这个,并没有得到任何答案,我的特殊情况。 我以一种简单的方式使用entity framework。 我正在尝试将记录添加到Memberproduct表中。 但是我得到了一个没有意义的例外。 任何想法在这里有什么问题? MemberProduct类: public class MemberProduct :ISaleable { public void ProcessSale() { throw new NotImplementedException(); } private int id { get; set; } private string productName { get; set; } private decimal price { get; set; } private TaxClass taxClass { get; set; } private int quantity { get; set; } […]

GetOriginalTypeParameterType throws未将对象引用设置为对象exception的实例

参考: 动态如何用作通用? public void CheckEntity(int entityId, string entityType = null) { dynamic AnyObject = Activator.CreateInstance(“Assembly”,”Assembly.Models.DbModels.” + entityType).Unwrap(); CheckWithInference(AnyObject, entityId); } private static void CheckWithInference(T ignored, int entityId) where T : class { Check(entityId); } private static void Check(int entityId) where T : class { using (var gr = new GenericRepository()) { } } 这与CheckEntity(16,”Container”);一起进入CheckEntity(16,”Container”); 。 […]

加载EntityFramework 4.3.1时出错

我在C#中创建了一个MVC应用程序。 我在我的解决方案中创建了一个名为PhoneDomain的新项目。 这样做的目的是将我的数据和域层与实际问题分开。 我右键单击该项目并转到“添加库包参考”,我尝试添加EntityFramework包(版本4.3.1)。 它说“ Operation Failed ”“ This package contains an init.ps1 file and needs to be installed from the Package Manager Console ”。 所以我在Visual Studio中打开了Package Manager控制台,并在控制台窗口中输入以下内容: install-package EntityFramework -project PhoneDomain 几秒钟后,它安装了软件包并说Successfully added ‘EntityFramework 4.3.1’ to PhoneDomain 问题是,当我运行我的应用程序时,我收到以下错误消息: Could not load file or assembly ‘EntityFramework, Version=4.3.1.0, Culture=neutral’ or one of its dependencies. The system […]

Ninject 3 InRequestScope不为同一请求返回相同的实例

最近,我将我的一个MVC3项目从Ninject 2升级到Ninject 3。 在几分钟后试图找到为什么InRequestScope不再可用,我发现这现在是Ninject.Web.Common的扩展。 现在,当我尝试运行应用程序时,Ninject的工作方式就像所有与范围InRequest绑定的类型都是InTransientScope; 每次都会创建一个新实例。 在我inheritance自NinjectModule的类中,我有一个简单的绑定: Bind().ToSelf().InRequestScope(); 在我的控制器中,我有2个标有Ninject属性的ViewModel.Activity类型的属性。 [Inject] public ViewModel.Activity Activity { get; set; } [Inject] public ViewModel.Activity Activity1 { get; set; } 如果我在调试模式中查看两个属性的HashCode的值,那么它们都有不同的值,但HttpContext是相同的; 我在同一个请求中。 我错过了如何使用Ninject 3的新版本正确使用新的Ninject.Web.Common.InRequestScope? 非常感谢你。

带有语句体的lambda表达式无法转换为nopCommerce 中的表达式树

我尝试在nopCommerce 3.0中创建一个linq连接查询。 我加入linq的两张桌子并写 代码成功了。 但视觉工作室的知识分子显示出错误 具有语句主体的lambda表达式无法转换为表达式树 请看下面的代码 var roles = _customerEventRoleRepository.Table.Where(c => c.EventId == selevent) .Join ( _customerRepository.Table, cev => cev.CustomerId, c => c.Id, (cev, c) => { var cust = new CustomerEventRolesModel(); cust.Id = cev.Id; cust.CustomerId = c.Id; cust.Customer = c.Email; cust.ContactName = c.GetAttribute(SystemCustomerAttributeNames.FirstName); cust.CompanyName = c.GetAttribute(SystemCustomerAttributeNames.Company); cust.Speaker = cev.IsSpeaker; cust.Sponsor = cev.IsSponser; return […]