C# 无法从webforms解决方案访问便携式区域控制器
我创建了一个webforms网站,它同时运行webforms和MVC4.0。我已经按照中的步骤创建了一个MVC可移植区域,并试图使用nuget的MvcContrib将其实现到我的webforms解决方案中 我在webforms solutions中添加了一个Areas文件夹,其中保存了portable Areas/view文件夹中的web.config文件。此外,我还在我的主要webforms项目中添加了对可移植区域的引用。我还改变了我的可移植区域中的所有视图,将其构建为嵌入式资源 然而,当我试图在浏览器中访问我的便携式区域控制器时,我得到了一个错误。 我的webforms解决方案似乎找不到可移植区域控制器/视图,因为它在我的webforms解决方案中搜索视图而不是我的可移植区域 我的便携区中的AreaRegistration类如下所示:C# 无法从webforms解决方案访问便携式区域控制器,c#,asp.net-mvc,C#,Asp.net Mvc,我创建了一个webforms网站,它同时运行webforms和MVC4.0。我已经按照中的步骤创建了一个MVC可移植区域,并试图使用nuget的MvcContrib将其实现到我的webforms解决方案中 我在webforms solutions中添加了一个Areas文件夹,其中保存了portable Areas/view文件夹中的web.config文件。此外,我还在我的主要webforms项目中添加了对可移植区域的引用。我还改变了我的可移植区域中的所有视图,将其构建为嵌入式资源 然而,当我试
public class DemoAreaRegistration : PortableAreaRegistration
{
public override string AreaName
{
get { return "Demo"; }
}
public override void RegisterArea(AreaRegistrationContext context, IApplicationBus bus)
{
RegisterRoutes(context);
bus.Send(new PortableAreaStartupMessage("Registering PortableArea Area"));
RegisterAreaEmbeddedResources();
}
private void RegisterRoutes(AreaRegistrationContext context)
{
context.MapRoute(
AreaName + "_scripts",
base.AreaRoutePrefix + "/Scripts/{resourceName}",
new {controller = "EmbeddedResource", action = "Index", resourcePath = "scripts"},
new[] {"MvcContrib.PortableAreas"}
);
context.MapRoute(
AreaName + "_images",
base.AreaRoutePrefix + "/images/{resourceName}",
new {controller = "EmbeddedResource", action = "Index", resourcePath = "images"},
new[] {"MvcContrib.PortableAreas"}
);
context.MapRoute(
AreaName + "_default",
base.AreaRoutePrefix + "/{controller}/{action}/{id}",
new {action = "Index", id = UrlParameter.Optional},
new[] {"PortableArea.Areas.Demo.Controllers", "MvcContrib"}
);
}
}
回答
在Web.Config中,为每种文件类型添加:
<system.webServer>
<handlers>
<add name="js" path="*.js" verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="File" preCondition="integratedMode" />
</handlers>
</system.webServer>
这将使IIS尝试使用已定义的路由,而不是搜索静态文件