我想避免打电话
AreaRegistration.RegisterAllAreas()
在我的global.asax中,因为我试图将所有启动逻辑移动到App_Start文件夹中的各个类中.但是,我没有成功地让它发挥作用.第一个选项尝试使用这样的代码:
[assembly: PreApplicationStartMethod(typeof(Startup), "PreInit")]
namespace Foo
{
public class Startup {}
}
Run Code Online (Sandbox Code Playgroud)
PreApplicationStartMethod来自System.Web名称空间的位置.在这种情况下,对寄存器区域的调用过早发生.
第二种方法基于David Ebbo的这篇文章,使用WebActivator:using System.Web.Mvc;
[assembly: WebActivatorEx.PostApplicationStartMethod
(typeof(AreaDemo.AreaConfig), "RegisterAreas")]
namespace AreaDemo
{
public class AreaConfig
{
public static void RegisterAreas()
{
AreaRegistration.RegisterAllAreas();
}
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,尽管没有抛出错误,但尝试导航到该区域失败(好像注册从未发生过).
使用程序集指令而不是从Global.asax直接调用,从启动类中注册ASP.NET MVC 5中的区域的正确方法是什么?
更新1:这是我的AreaRegistration代码:
public class AdminAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Admin";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", …Run Code Online (Sandbox Code Playgroud) 安装Microsoft.Owin后,我收到此错误.*.目标.Net框架:4.5.2.Web Activator:2.2.0我在另一个项目中有相同的设置,似乎工作正常.请帮我调试或解决这个问题.
我到目前为止做了什么: -
完整错误详情: -
参数计数不匹配.描述:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.
Stack Trace:
[TargetParameterCountException: Parameter count mismatch.]
System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj,
BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo
culture) +11403690
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +54
WebActivatorEx.BaseActivationMethodAttribute.InvokeMethod() +73
WebActivatorEx.ActivationManager.RunActivationMethods(Boolean designerMode)
+637
WebActivatorEx.ActivationManager.Run() +103
[InvalidOperationException: The pre-application start initialization method
Run on type WebActivatorEx.ActivationManager threw an exception with the
following error message: Parameter count mismatch..]
Run Code Online (Sandbox Code Playgroud)
这是package.config: -
<package id="EntityFramework" version="6.1.3" targetFramework="net452" />
<package …Run Code Online (Sandbox Code Playgroud) 在安装WebActivatorEx nuget包后尝试访问页面时,我不断收到以下ArgumentException.
Server Error in '/PharmaDotnet/ux' Application.
The type Pharma.Mvc.Startup doesn't have a static method named Configuration
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.ArgumentException: The type Pharma.Mvc.Startup doesn't have a static method named Configuration
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin …Run Code Online (Sandbox Code Playgroud) 我正在建设一个新项目.

我有一个名为"bootstrapper"的独立项目,它包含IOC和WebActivator.我的问题是包含WebActivator的类甚至没有在调试中加载!可能是我错过了什么?
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(IocConfig), "RegisterDependencies")]
public class IocConfig
{
public static void RegisterDependencies()
{
//..........
}
}
Run Code Online (Sandbox Code Playgroud)