MVC 的 ReturnUrl = Default.aspx?
我正在尝试保护整个 MVC 站点,因此在 Home 控制器之前,我添加了一个 [Authorize] 属性。
现在,如果您从 Visual Studio 运行它或使用根 URL 导航(例如 http://localhost:2897),它会执行此操作正如预期的那样,重定向到登录页面。但是,重定向后地址栏中的 URL 如下所示: http:// localhost:2897/Account/LogOn?ReturnUrl=%2fdefault.aspx%3f
我还没有对此进行测试,因为我还没有实现我的身份验证代码。然而,这对我来说似乎是一个大问题,因为我的项目中没有default.aspx!
我在 web.config 中的身份验证标记如下所示:
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" defaultUrl="~/Home/Index" timeout="2880"/>
</authentication>
为什么它不选择此路由作为默认 ReturnUrl 而不是 default.aspx?
I'm trying to secure my entire MVC site, so before the Home controller, I added an [Authorize] attribute.
Now if you run it from Visual Studio or navigate using the root URL (e.g. http://localhost:2897) it does redirect to the login page, as expected. However the URL in the address bar after redirection looks like this: http://localhost:2897/Account/LogOn?ReturnUrl=%2fdefault.aspx%3f
I haven't tested this out, seeing as I have not implemented my authentication code. However, this looks like a big problem to me, since I do not have a default.aspx in my project!
My authentication tag in the web.config looks like this:
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" defaultUrl="~/Home/Index" timeout="2880"/>
</authentication>
Why doesn't it pick up this route as the default ReturnUrl instead of default.aspx?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当
ReturnUrl
时,ASP.NET(准确地说,FormsAuthentication.RedirectFromLoginPage
)总是忽略web.config
中的defaultUrl
设置代码> 参数存在。仅当您直接进入登录页面而不传递任何ReturnUrl
参数时,才会受到尊重。ASP.NET MVC 项目模板提供了一个空白的
Default.aspx
模板来处理类似于 IIS 经典管道模式中的请求。你应该对此没问题。ASP.NET (to be precise,
FormsAuthentication.RedirectFromLoginPage
) always ignores thedefaultUrl
setting inweb.config
when aReturnUrl
parameter is present. It's only honored when you go directly to the login page without passing anyReturnUrl
parameters.ASP.NET MVC project template provides a blank
Default.aspx
template to handle requests like that in IIS Classic pipeline mode. You should be fine with that.