Tag: asp.net mvc

子应用程序中的Asp.net MVC Catchall路由

我有一个MVC应用程序,其子应用程序在IIS中运行另一个MVC项目。 两者都使用相同的版本框架并在单独的应用程序池上运行。 我的问题是,我无法让子应用程序在根网站的这个虚拟应用程序文件夹中工作。 我收到403.14 Forbidden错误 。 如果我在子应用程序上启用目录列表,我只需获取MVC应用程序文件的列表。 我想,我已将问题缩小到路由; 子应用程序有一个自定义catchall路由,它处理对站点的所有请求,它是一个CMS应用程序。 没有注册其他路线。 这是我的自定义路线的代码: RouteTable.Routes.Insert(0,new CmsRoute( “{*path}”, new RouteValueDictionary(new { controller = “Page”, action = “Index” }), new MvcRouteHandler())); 在自己的站点中的主根应用程序之外运行此应用程序,它工作正常,所有请求都由我的自定义路由处理。 但是当我尝试将其作为子应用程序运行时,路由处理程序永远不会被命中。 如果我添加开箱即用的标准默认MVC路由: routes.MapRoute( name: “Default”, url: “{controller}/{action}/{id}”, defaults: new { controller = “Home”, action = “Index”, id = UrlParameter.Optional } ); 然后MVC启动并尝试为请求找到匹配路由。 所以我的问题是为什么我的catchall路由在IIS中的子应用程序中运行时不起作用? 注意:我尝试使用虚拟应用程序文件夹的名称为我的自定义路由中的url加前缀,但它仍然不起作用,例如: RouteTable.Routes.Insert(0,new CmsRoute( “subapplication/{*path}”, new […]

Html.ValidationMessageFor Text Color

可能是一个简单的问题,但我似乎无法找到答案。 使用MVC 2我有一系列的Html.ValidationFor控件。 我想为文本分配一个CSS类,似乎无法做到。 Model.Chest, new { @class = “textBoxMeasure” })%> Model.Chest) %> 如果我尝试与textbox相同的方法,因为它需要一个字符串,因为它需要一个字符串,当我把一个字符串放在它仍然不会工作! 谢谢

Hangfire Dashboard授权配置不起作用

我已经下载了nu-get软件包Hangfire.Dashboard.Authorization 我正在尝试按照以下文档配置基于OWIN的授权,但我得到intellisense错误DashboardOptions.AuthorizationFilters is obsolete please use Authorization property instead 我也得到intellisense错误The type or namespace AuthorizationFilter and ClaimsBasedAuthorizationFilterd not be found using Hangfire.Dashboard; using Hangfire.SqlServer; using Owin; using System; namespace MyApp { public class Hangfire { public static void ConfigureHangfire(IAppBuilder app) { GlobalConfiguration.Configuration .UseSqlServerStorage( “ApplicationDbContext”, new SqlServerStorageOptions { QueuePollInterval = TimeSpan.FromSeconds(1) }); var options = new DashboardOptions […]

MVC:我可以在控制器中使用ModelState吗?

我可以这样做吗? … using System.Web.Mvc; … public static class aaa { public static test() { if (something) ModelState.AddModelError(“”, “test”); } } 内部控制器调用: … public class mycontroler { public void Index() { …. aaa.test(); …. } } 可能吗? 我想控制控制器另一部分中的类内部的代码。

使用属性路由时是否可以更改路由表中的路由顺序?

所以,我正在将区域从使用AreaRegistration切换到使用属性路由。 我遇到的问题似乎是由路由加载到路由表中的顺序引起的。 我通过最后加载有问题的路由解决了AreaRegistration中的问题,这样只有当所有其他路由不匹配时才会匹配该路由。 使用属性路由,这似乎不可能。 我在创建路由时有Order参数,但这不会影响路由表的方式,除非非常狭窄。 这是我在AreaRegistration文件中的路由: context.MapRoute( name: “ActionItems_home”, url: “ActionItems/{group}/{statuses}/{overdueOnly}”, defaults: new { controller = “Home”, action = “Index”, group = “All”, statuses = “New,Open”, overdueOnly = false }, namespaces: new string[] { “IssueTracker.Areas.ActionItems.Controllers” } ); 现在,当我尝试将其切换到属性路由时,唯一接近工作的是: [Route(“”, Order = 4)] [Route(“{group:regex(^(?!Item|DecisionLogs))?}”, Order = 3)] [Route(“{group:regex(^(?!Item|DecisionLogs))}/{statuses=New,Open?}”, Order = 2)] [Route(“{group:regex(^(?!Item|DecisionLogs))}/{statuses=New,Open}/{overdueOnly:bool=false?}”, Order = 1)] 请注意,我必须放入正则表达式,因为否则不会调用Item控制器 […]

如何在asp.net vnext中注册身份validation类型名称

因此,我正在更新MongoDB的开源asp.net身份提供程序,以便与Asp.Net Identity 3.0(又名vnext)一起使用。 到目前为止,我已经能够注册提供程序并创建用户,但是当使用SignInManager时,如果提供了正确的UserName / Pass,我会收到错误 InvalidOperationException:未接受以下身份validation类型:Microsoft.AspNet.Identity.Application 我已经将错误跟踪到这里https://github.com/aspnet/HttpAbstractions/blob/dev/src/Microsoft.AspNet.PipelineCore/DefaultHttpResponse.cs 但我似乎无法看到SignInContext.Accepted名称被添加到SignInContext的位置。 我正在使用VS14 CTP2中使用的所有vnext库的Alpha-2版本 下面是我的Startup.cs public void Configure(IBuilder app) { try { // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 var configuration = new Configuration(); configuration.AddJsonFile(“config.json”); configuration.AddEnvironmentVariables(); // app.UseLogRequests(“try”); app.UseErrorPage(ErrorPageOptions.ShowAll); app.UseServices(services => { services.AddIdentity() .AddMongoDB(configuration.Get(“Data:MongoIdentity:ConnectionString”), configuration.Get(“Data:MongoIdentity:DBName”)) .AddHttpSignIn(); // Add MVC services to the services […]

在MVC类上创建主键字段

我是MVC和C#的新手。 我偶然发现它并发现它很有趣。 我遇到了一个不允许我继续的问题。 这是我的代码: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace MyHotel.Models { public class AccountTypes { public int AccountTypeID { get; set; } public string AccountTypeName { get; set; } } } 之后我创建了控制器和视图。 为此,我一直有这个错误: 在模型生成期间检测到一个或多个validation错误: System.Data.Edm.EdmEntityType: : EntityType ‘AccountTypes’ has no key defined. Define the key for this EntityType. System.Data.Edm.EdmEntitySet: […]

URL.Action与字符串数组?

我有一个字符串数组,我需要在Url.Action的查询字符串中传递。 Url.Action(“Index”, “Resource”, new { FormatIds = Model.FormatIDs}) 现在,链接在我的浏览器中显示为System.String []而不是查询字符串。 是否有可能让MVC通过模型绑定自动执行此操作? 我需要它与我的控制器动作绑定,如: public ActionResult Index(string[] formatIDs)

最佳模拟图书馆

哪个是C#3.0 / ASP.NET MVC最好的模拟库? 为什么?

无法从’System.Data.Objects.ObjectParameter’转换为’System.Data.Entity.Core.Objects.ObjectParameter’

在创建ADO.NET实体数据模型时 ,发生以下错误: 错误66参数10:无法从’System.Data.Objects.ObjectParameter’转换为’System.Data.Entity.Core.Objects.ObjectParameter’D:\ Aziz \ Aziz Project \ Development \ Running Development \ Web \ pos \ pos \ Model1.Context.cs 351 278 pos 怎么可能解决这个错误?