Tag: asp.net mvc

重写控制器AuthorizeAttribute只需一个动作

我有一个用AuthorizeAttribute装饰的控制器。 控制器包含几个操作,除了需要CustomAuthorizeAttribute提供的一些自定义身份validation的操作之外,所有这些操作都需要身份validation。 我的问题是,一旦我在控制器级别添加了[Authorize],我可以用一个动作[CustomAuthorize]覆盖它(或删除它)吗? 还是必须从控制器级别删除[授权],并将其单独添加到其他任何操作? 我纯粹是为了方便,因为我很懒,不想用AuthorizeAttribute来装饰每一个动作。 [Authorize] public class MyController : Controller { //requires authentication public ViewResult Admin() { return View(); } //… a lot more actions requiring authentication //requires custom authentication [CustomAuthorize] //never invoked as already failed at controller level public ViewResult Home() { return View(); } }

如何在asp.net MVC中gzip内容?

如何压缩由asp.net mvc应用程序发送的输出?

如何使用C#关键字作为属性名称?

使用asp.net MVC我想在视图中做到这一点: <%= Html.TextBox("textbox1", null, new { class="class1" }) %> 这个语句不能编译,因为class是C#中的关键字。 我想知道怎样才能逃避这个编译的属性名称。 如果将“class”属性更改为“Class”(大写C),则可以将其编译。 但这是不合适的,因为严格的xhtml说,所有的属性(和元素)名称必须是小写。

POSTstring到ASP.NET Web Api应用程序 – 返回null

我试图从客户端传递一个string到ASP.NET MVC4应用程序。 但是我不能接收string,要么是null,要么post方法找不到(404错误) 客户端代码传输string(控制台应用程序): HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:49032/api/test"); request.Credentials = new NetworkCredential("user", "pw"); request.Method = "POST"; string postData = "Short test…"; byte[] byteArray = Encoding.UTF8.GetBytes(postData); request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = byteArray.Length; Stream dataStream = request.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); WebResponse response = request.GetResponse(); Console.WriteLine(((HttpWebResponse)response).StatusDescription); dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = […]

WebAPI中的DependencyResolver.SetResolver和HttpConfiguration.DependencyResolver之间有什么区别

我有现有的项目,它使用AutoFac作为IoC。 在注册码我有这些行: var resolver = builder.Build(); DependencyResolver.SetResolver(new AutofacDependencyResolver(resolver)); config.DependencyResolver = new AutofacWebApiDependencyResolver(resolver); 所以我的问题是什么DependencyResolver.SetResolver和HttpConfiguration.DependecyResolver之间的区别? 我为什么要分配他们?

点击描述时勾选checkbox

我将创build一个由jQuery和JSON构build的checkbox列表。 该列表将是消息可以发送到的组的select。 它可能是更多的团体之一。 这部分我可以弄清楚。 我遇到的问题是如何启用描述,以便当我点击描述时,checkbox被选中。 <div> <label for="group"> Select lists </label> </div> <div> <input type="checkbox" name="group" id="group" value="1" title="Main List" />Main List <input type="checkbox" name="group" id="group" value="2" title="Secondary List" />Secondary List </div>

validationasp.net mvc中的下拉列表

//in controller ViewBag.Categories = categoryRepository.GetAllCategories().ToList(); //in view @Html.DropDownList("Cat", new SelectList(ViewBag.Categories,"ID", "CategoryName")) 我怎么能这样做,默认情况下它说:“ – select类别 – ” 并validation选中的东西(客户端和模型) 谢谢

EntityType'Category'没有定义键。 定义这个EntityType的关键

开发一个基本的ASP.net MVC 4应用程序。 它是一个简单的产品目录应用程序,在我有2个数据库表(“类别”和“产品”) “产品”表中有“类别ID”(类别表中的主键)的外键引用。 当我运行应用程序,我得到错误信息(下面列出)。 System.Data.Entity.Edm.EdmEntityType: : EntityType 'Category' has no key defined. Define the key for this EntityType. System.Data.Entity.Edm.EdmEntitySet: EntityType: EntitySet 'Category' is based on type 'Category' that has no keys defined 这看起来像一个新手常见的错误,我没有检查所有相关的解决scheme,“实体键”没有定义的键。 但仍然是我的问题没有解决,请帮助我理解这个问题,以及这个问题的正确解决scheme是什么。 以下是我的模型类 Category.cs namespace ChemicalStore.Models { public partial class Category { public int CatId { get; set; } public string […]

值不能为空。 参数名称:值,CreateIdentityAsync?

我创build了一个实现IUser<int>的ViewModel( UserModel )(用于定制ASP.NET Identity 2.0) public class UserModel : IUser<int> { public int Id { get; set; } public string SecurityStamp { get; set; } [Display(Name = "Name")] public string FirstName { get; set; } [Display(Name = "Last Name")] public string LastName { get; set; } public string FullName { get; set; } [Display(Name = […]

StyleBundle索引超出了数组的范围

我想包括像这样的目录中的所有文件: bundles.Add(new StyleBundle("~/Content/simpliq_css").Include( "~/Content/simpliq/*.css" )); 但是我得到这个错误Index was outside the bounds of the array 红线是: @Styles.Render("~/Content/simpliq_css") [IndexOutOfRangeException: Index was outside the bounds of the array.] System.String.get_Chars(Int32 index) +0 Microsoft.Ajax.Utilities.CssParser.Append(Object obj, TokenType tokenType) +402 Microsoft.Ajax.Utilities.CssParser.AppendCurrent() +74 Microsoft.Ajax.Utilities.CssParser.ParseElementName() +321 Microsoft.Ajax.Utilities.CssParser.ParseSimpleSelector() +54 Microsoft.Ajax.Utilities.CssParser.ParseSelector() +555 Microsoft.Ajax.Utilities.CssParser.ParseRule() +165 Microsoft.Ajax.Utilities.CssParser.ParseStylesheet() +186 Microsoft.Ajax.Utilities.CssParser.Parse(String source) +946 Microsoft.Ajax.Utilities.Minifier.MinifyStyleSheet(String source, CssSettings settings, CodeSettings scriptSettings) +439 Microsoft.Ajax.Utilities.Minifier.MinifyStyleSheet(String […]