我现在正在一个项目中测试名为Areas的MVC 2 Preview 2的新功能.按照MSDN文章以及我创建了Areas文件夹的相关说明文档,然后是区域的名称文件夹,然后是其中的控制器和视图文件夹.当然路线类已经添加并且有效.
然后我将其中一个控制器和它的视图文件夹移动到该新区域.它无法在第一行运行aspx页面:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<OtherReferencedProjectNamespace.Entity>" %>
Run Code Online (Sandbox Code Playgroud)
使用语法分析器消息
"Cannot load the type: OtherReferencedProjectNamespace.Entity" /example entity name here/
Run Code Online (Sandbox Code Playgroud)
看起来没有引用先前使用的命名空间没有任何问题!迁移到某个区域的代码是否具有单独的命名空间引用?
没有对项目进行引用更改,只是将其中一个控制器与其视图文件一起移动到一个区域中.
我还没有解释,你有什么想法吗?
也许我不能正确理解MVC区域是如何工作的,但这让我有些困惑.
所以此时如果你启动应用程序并导航到/ MyArea /它应该加载AnArea控制器及其匹配视图.如果导航到/ MyArea/AnArea,它将显示相同的结果.
但是,如果您导航到/ AnArea /,仍然会找到控制器并显示以下错误消息:
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/anarea/Index.aspx
~/Views/anarea/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/anarea/Index.cshtml
~/Views/anarea/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml
Run Code Online (Sandbox Code Playgroud)
这是正确的行为吗?我原以为一个区域的控制器只能通过它自己的区域访问而不是全局访问.
如何在包含区域的ASP.NET MVC应用程序中将视图设置为域的主页.我需要一个特定区域的视图作为主页.怎么可以这样做?
我尝试使用以下代码但没有成功.
public static void RegisterRoutes(RouteCollection routes) {
routes.MapRoute(
name: "Home",
url: "",
defaults: new { controller = "Home", action = "Index" },
namespaces: new string[] { "WebApp.Areas.UI.Controllers" }
);
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试将我的MVC4应用程序从ASP.NET成员资格迁移到新的SimpleMembership,并且遇到了密码重置问题.在我的登录视图中,我有"忘记密码"超链接,该超链接对发送带有重置密码超链接的电子邮件的操作执行AJAX帖子(基于MSDN指南):
[HttpPost]
[AllowAnonymous]
public ActionResult ForgotPassword(string userName)
{
//get the user from database, validate it exists, etc.
var token = WebSecurity.GeneratePasswordResetToken(userName);
var resetLink = "<a href='" + Url.Action("ResetPassword", "Account", new {un = userName, rt = token}, "http") + "'>Reset Password</a>";
//send the email
return Json(new {result = "Email sent."});
}
Run Code Online (Sandbox Code Playgroud)
这很好,但出于某种原因,当我尝试使用重置密码链接时,我被重定向到登录屏幕,Fiddler显示401-Unauthorized.我已经尝试将链接复制/粘贴到浏览器地址栏中,并创建一个带有锚标记的垃圾HTML文件,但结果仍然是401.这是重置密码操作(也在来自的帐户控制器中) MVC4模板):
[HttpPost]
[AllowAnonymous]
public ActionResult ResetPassword(string un, string rt)
{
var model = new ResetPasswordViewModel {UserName = un, ResetToken = rt};
return View(model);
}
Run Code Online (Sandbox Code Playgroud)
我也尝试删除该HttpPost属性,但这也产生了401.我在这里缺少什么? …
asp.net-mvc asp.net-mvc-areas asp.net-mvc-4 simplemembership
我有这条路线:
我的网站路线WebSite/Global.asax.cs:
namespace WebSite
{
public class MvcApplication : HttpApplication
{
public static void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
...
routes.MapRoute(
"Default",
"Authenticated/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new[] { "WebSite.Controllers" }
);
...
}
void Application_Start()
{
...
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
...
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的管理区路线WebSite/Areas/Admin/AdminAreaRegistration.cs:
namespace WebSite.Areas.Admin
{
public class AdminAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Admin";
}
}
public override void RegisterArea(AreaRegistrationContext …Run Code Online (Sandbox Code Playgroud) asp.net-mvc asp.net-mvc-routing asp.net-mvc-areas asp.net-mvc-3
我正在尝试从另一个项目加载剃刀视图。我已经经历了几个不同的兔子洞,但到目前为止我还没有找到一种方法来完成这项工作。然而,根据我的研究,似乎有两种主要方法可以实现这一目标。
一种选择是使用嵌入式资源,然后将嵌入式文件提供程序连接到 razor 中。我可能是错的,但我认为这是 .net core 2.1 之前的方法。我的理解是,在 2.1 Razor 视图中,Razor 视图是在构建时编译的。将其设置为嵌入将保存实际文件,这对于旧的运行时编译很有用。
// Add the embedded file provider to be used with razor view templates
var viewAssembly = typeof(CoreStartup).GetTypeInfo().Assembly;
var fileProvider = new EmbeddedFileProvider(viewAssembly);
services.Configure<RazorViewEngineOptions>(o => o.FileProviders.Add(fileProvider));
services.AddTransient<ITemplateService, TemplateService>();
Run Code Online (Sandbox Code Playgroud)
另一种方法是将视图放入区域文件夹中。我什至找到了一个示例项目,它表明您完全可以做到这一点!但是,我一直无法找到获得相同结果的方法。
作为参考,这里是我尝试用来查找和渲染剃刀视图的服务。我需要从中获取 html 输出以帮助创建 html 电子邮件模板。
namespace TestApp.Services
{
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Options;
using Serilog;
public class TemplateService : …Run Code Online (Sandbox Code Playgroud) example.com如果可能,将我的正常域映射到例如没有区域。blog.example.com到一个名为blog.实际上有很多关于这个主题的帖子,特别是将子域映射到区域。
来自 SO:
其他:
而且可能还有更多。
但是有一个大问题,在 ASP.Net Core 3 中他们改变了很多东西,其中之一是一般的路由,请参阅mircosoft 的 devblog。基本上他们改变了它,所以现在一切都应该是端点。
至少从我的理解来看,所有的类 egMvcRouteHandler和接口 egIRouter现在基本上已经过时了。在 GitHub 存储库中搜索并挖掘了一段时间后,我找不到任何有用的东西。
SDK 3.0.100-preview6-012264,但试图尽快升级到
SDK 3.0.100-preview7-012821。c# subdomain asp.net-mvc-areas asp.net-core asp.net-core-3.0
我的MVC 3应用程序Auth和Users中有几个区域.我正在使用Phil Haacks Route Debugging工具查看我的路线列表,并根据我的网址查看哪一个被选中.
但是,有一些路由存在,我没有在我的AreaRegistration文件或Globalasax中创建,我不知道它们来自何处或如何摆脱它们.路线在下面以黄色突出显示.
您还可以看到我在Auth区域中创建了一个默认路由(以绿色突出显示),它只是指向我的Auth控制器的Login操作.我调试了RouteTable,它在AreaRegistration.RegisterAllAreas()时被添加; 方法被调用.但是,它也没有被添加到AreaRegistration中,因为它也已经逐步完成了.
ASP.NET MVC是否将此作为默认值添加,如果是这样,我可以以某种方式删除它吗?

我能够使用ASP.NET MVC 3和Ninject 2.2注入Logger对象到自定义ActionFilterAttribute感谢我在此得到的帮助后.
现在我想将自定义ActionFilterAttribute仅绑定到特定区域中的所有控制器.
我能够开始使用以下绑定,但它只处理某个区域中的一个控制器.我希望我的代码绑定到特定区域中的所有控制器.有任何想法吗?
/// <summary>
/// Load your modules or register your services here!
/// </summary>
/// <param name="kernel">The kernel.</param>
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<ILogger>().To<Log4NetLogger>().InRequestScope();
kernel.BindFilter<TestLoggingAttribute>(
FilterScope.Controller, 0)
.WhenControllerType<OrganizationController>();
}
Run Code Online (Sandbox Code Playgroud) dependency-injection ninject asp.net-mvc-areas action-filter asp.net-mvc-3
我知道错误"没有为此对象定义的无参数构造函数"已被问过一百万次.我的情况有所不同
我有一个工作的应用程序.许多控制器和一个有很多控制器的区域.我刚刚添加了一个新区域.我添加了一个控制器,然后是该控制器的链接.现在我得到"为此对象定义的无参数构造函数"错误
我之前已经看到并克服了这个问题,但它实际上只发生在每5个月一次.每次我完全忘记(压抑)答案.
请帮忙
RAIF
asp.net-mvc ×6
c# ×2
.net-core ×1
asp.net-core ×1
ninject ×1
razor ×1
structuremap ×1
subdomain ×1