重定向到路由结果资源未找到
我有一个操作过滤器,它实现基本检查以查看用户是否经过身份验证。
如果用户没有经过身份验证我已经实现了这个:
var RouteValue = 新 RouteValueDictionary { {“控制器”,“权限”}, {“操作”,“禁止访问”} }; filterContext.Result = new RedirectToRouteResult(routeValue); base.OnActionExecuting(filterContext);
好的,这有效并将用户指向:
http://localhost:/Permission/NoAccess,
但是当我重新加载项目时问题开始发生,然后用户被重定向到:
http://localhost:/Views/Permission/NoAccess .aspx
和我收到错误:找不到资源。
有点困惑为什么它可以工作一次然后在重新加载后再次中断?有什么建议吗?也许我应该使用另一种方法进行重定向?
使用 IIS Express、Visual Studio 2010、MVC2
i have an action filter which implements a basic check to see if the user is authenticated.
if the user is not authenticated i've implemented this:
var routeValue = new RouteValueDictionary { {"Controller", "Permission"}, {"Action", "NoAccess"} }; filterContext.Result = new RedirectToRouteResult(routeValue); base.OnActionExecuting(filterContext);
ok this works and points the user to:
http://localhost:/Permission/NoAccess
but the problem starts to happen when i reload my project and the user is then redirected to:
http://localhost:/Views/Permission/NoAccess.aspx
and i get the error: The resource cannot be found.
slightly confused why it works once then breaks again after a reload? any suggestions?maybe i should be redirecting using another method?
using IIS express, visual studio 2010, MVC2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这看起来像是 Visual Studio 的一个不幸的功能...
如果您在 Visual Studio 中打开视图 NoAccess.aspx,然后按 F5,Visual Studio 将使用 URL
http:/localhost:11111/Views/ 打开 Internet Explorer权限/NoAccess.aspx
。此 URL 可能适用于经典 ASP.NET 应用程序,但不适用于 ASP.NET MVC 应用程序。这基本上是 Visual Studio 中的错误,当然不是您的应用程序中的错误。如果打开 .cs 文件,然后按 F5,Visual Studio 将使用 URL
http:/localhost:11111/
启动 Internet Explorer。我不确定这是否适用于您的问题,因为我不知道您所说的“重新加载项目”是什么意思。但这可能就是你所看到的。
This looks like an unfortunate feature of Visual Studio...
If you have the view NoAccess.aspx open in Visual Studio and then press F5, Visual Studio opens the Internet Explorer with the URL
http:/localhost:11111/Views/Permission/NoAccess.aspx
. This URL might work for a classic ASP.NET application, but it doesn't for ASP.NET MVC applications. And it's basically a bug in Visual Studio and certainly not in your application.If you open a .cs file and then press F5, Visual Studio will start Internet Explorer with the URL
http:/localhost:11111/
.I'm not sure this applies to your problem because I don't know what you mean by reload your project. But it might be what your seeing.