在应用程序启动时,在登录之前,我想要一些"页面",它们与我的登录页面位于同一文件夹中,以便可以转到。
在旧的aspx中,您将web.config放在这些页面所在的文件夹中,并执行了以下操作:
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
在MVC领域,正确的方法是什么?我试着不在我想要访问的控制器方法上加上[授权]标签,但这似乎并不能减少它
有趣的新证据。。。
我转到了我的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" }) });
它又开始失败了。。。
有人有什么想法吗?
感谢您的帮助。
请记住,web.config文件中的"位置"是基于URL的,而不是基于文件夹的。因此,如果你有一个GuestController,你可以说:
<location path="Guest">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>