在应用启动时,在登录之前,我想要一些“页面”,它与我的登录页面位于同一个文件夹中,可以转到。
在旧的aspx域中,你在这些页面所在的文件夹中删除了web.config并执行了此操作:
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
在MVC土地上执行此操作的正确方法是什么?我试着不把[Authorize]标签放在我想要访问的控制器方法上,但这似乎并没有削减它。
有趣的新证据......
我去了我的web.config
我改变了这个:
<authorization>
<deny users="?" />
<allow users="*" />
<deny users="*" verbs="OPTIONS, PROPFIND, HEAD" />
</authorization>
为:
<authorization>
<allow users="*" />
</authorization>
现在如果我键入此路径:
http://localhost/StudentPortal3G/Account/ChangePasswordSelfService
它有效,
但如果我输入此路径:
http://localhost/StudentPortal3G/Account.mvc.aspx/ChangePasswordSelfService
它没有(这是Atml.ActionLink(...)生成的路径)
我认为这必须是一个线索,我认为我的路由是错误的,但我没有看到它。
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{resource}.css/{*pathInfo}");
routes.IgnoreRoute ( "{resource}.jpg/{*pathInfo}" );
routes.IgnoreRoute ( "{resource}.jpg" );
routes.IgnoreRoute ( "{resource}.gif/{*pathInfo}" );
RouteTable.Routes.IgnoreRoute("{folder}/{*pathInfo}", new { folder = "Assets" });
RouteTable.Routes.IgnoreRoute ( "{folder}/{*pathInfo}", new { folder = "Images" } );
routes.IgnoreRoute ( "{*favicon}", new
{
favicon = @"(.*/)?favicon.ico(/.*)?"
} );
routes.IgnoreRoute("elmah.axd");
//routes.MapRoute("About", "Home/About", new { controller = "Home", action = "About", id = "" });
// you have to add this IgnoreRoute so that the PDFX pages get handled like a regular *.aspx page, not a MVC page. - EWB
routes.IgnoreRoute("{resource}.pdfx");
// allow MVC to run on IIS 5,6,7
//http://stackoverflow.com/questions/57712/mvc-net-and-iis-5
routes.Add(new Route("{controller}.mvc.aspx/{action}", new MvcRouteHandler()) { Defaults = new RouteValueDictionary(new { controller = "Email" }) });
routes.MapRoute(
"Email", // Route name
"{controller}/{action}/{id}", // URL with parameters
null // Parameter defaults
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
routes.MapRoute(
"Default2", // Route name
"{controller}.aspx/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults );
);
routes.MapRoute(
"Default3", // Route name
"{controller}.mvc.aspx/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults );
);
}
更多信息: 如果我评论这些,HTML.ActionLink开始生成有效的链接。
routes.Add(new Route("{controller}.mvc.aspx/{action}", new MvcRouteHandler()) { Defaults = new RouteValueDictionary(new { controller = "Email" }) });
routes.MapRoute(
"Default2", // Route name
"{controller}.aspx/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults );
);
routes.MapRoute(
"Default3", // Route name
"{controller}.mvc.aspx/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults );
);
然后,如果我放回这个(这需要在服务器2008上工作我相信):
routes.Add(new Route("{controller}.mvc.aspx/{action}", new MvcRouteHandler()) { Defaults = new RouteValueDictionary(new { controller = "Email" }) });
它又开始失败了......
有没有人有任何想法?
感谢任何帮助。
答案 0 :(得分:2)
请记住,web.config文件中的“位置”是基于URL的,而不是基于文件夹的。所以如果你有一个GuestController,你可以说:
<location path="Guest">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>