应用于 AccountController.LogOn 时,MVC Preview 2 失败
当尝试将 [RequireHttps] 应用于 ASP.NET MVC 2 Preview 2 中的 AccountController.Logon 时,出现以下错误:
ASP.NET 检测到 URL 中存在无效字符。
这是因为 ASP.NET 已将我的请求从
http://example.com/admin
重写为
https://example.com/account/logon%3FReturnUrl=/admin
ASP.NET 本身添加了 ReturnURL
(不是 ASP.NET MVC),但 RequireHttps
属性正在重定向并弄乱了 URL。
%3F
而不是 ?
正在破坏页面。
我认为从技术上来说这是 ASP.NET 中的一个错误。有解决方法吗? 我在想也许有一种方法可以处理 global.asax 中的“未经身份验证”事件 - 或者可能只是修复 RequireHttpsAttribute 的源。
[RequireHttps]
public ActionResult LogOn()
{
return View(DefaultModel);
}
<authentication mode="Forms">
<forms loginUrl="~/account/logon"/>
</authentication>
这是一个类似但不同的问题
编辑:我刚刚尝试手动输入 http://example.com/accout/login?cat=dog
,但它仍然重定向到无效的 URL:account/logon%3Fcat=dog
>。我最初认为这与会员资格提供者和 [RequireHttps]
之间的冲突有关,但它看起来只是一个基本错误,所以我想我必须自己修复源。
When trying to apply [RequireHttps] to AccountController.Logon in ASP.NET MVC 2 Preview 2 I get the following error :
ASP.NET detected invalid characters in the URL.
This is because ASP.NET has rewritten my request from
http://example.com/admin
to
https://example.com/account/logon%3FReturnUrl=/admin
It is ASP.NET itself that has added ReturnURL
(not ASP.NET MVC), but it is the RequireHttps
attribute that is redirecting and messing up the URL.
The %3F
instead of ?
is breaking the page.
I think its technically a bug in ASP.NET. Is there a workaround?
I'm thinking maybe a way to handle the 'unauthenticated' event in global.asax - or possibly just fixing the source for RequireHttpsAttribute.
[RequireHttps]
public ActionResult LogOn()
{
return View(DefaultModel);
}
<authentication mode="Forms">
<forms loginUrl="~/account/logon"/>
</authentication>
Here's a similar, but different question
Edit: I just tried manually entering in http://example.com/accout/login?cat=dog
and it still redirected to an invalid URL : account/logon%3Fcat=dog
. I originally thought it was related to a conflict between the membership provider and [RequireHttps]
but it looks like just a basic bug so I think I'll have to just fix the source myself.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设这是 ASP.NET MVC 2 Preview 2 中的临时错误,这就是我所做的:
应用 [RequireHttps2] 属性而不是 [RequireHttps]
公共类 RequireHttps2Attribute : FilterAttribute, IAuthorizationFilter
{
}
Assuming this is a temporary bug in ASP.NET MVC 2 Preview 2 this is what I did :
Applied the [RequireHttps2] attribute instead of [RequireHttps]
public class RequireHttps2Attribute : FilterAttribute, IAuthorizationFilter
{
}
这在 ASP.NET MVC2 RC 中似乎已修复。
现在被重写为正确的 URL:
This appears fixed in ASP.NET MVC2 RC.
now gets rewritten to the correct URL: