运行时重定向到操作
我正在开发MVC3项目并遇到这种情况。仅在运行时。
我使用默认帐户控制器登录。如果登录成功,我需要重定向到另一个区域,就像这样:
if (Membership.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
SessionBag.Current.UserName = model.UserName;
if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
&& !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
{
return Redirect(returnUrl);
}
else
{
//Here This doesn´t work at run time.
return RedirectToAction("MenuInicial", "Menu", new { area = "Configuration" });
}
}
else
{
ModelState.AddModelError("", "The user name or password provided is incorrect.");
}
它在开发时运行正常,但在发布后该网站无法工作。
我的第一个链接(它显示欢迎并提供登录按钮)
[http://localhost/mobile1]
单击登录按钮后: [http://localhost/mobile1#/Mobile1/Account/LogOn]
输入用户名和密码后显示 则加载页面时出错
如果手动将链接
[http://localhost/mobile1#/Mobile1/Account/LogOn] 更改为 [localhost/mobile1/Account/LogOn], 同样的错误发生。
非常感谢您的帮助。
I'm developing MVC3 project and have this situation. only at runtime.
I'm using the default Account controller to login. if login succeed i need to redirect to another area just somethhing like this:
if (Membership.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
SessionBag.Current.UserName = model.UserName;
if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
&& !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
{
return Redirect(returnUrl);
}
else
{
//Here This doesn´t work at run time.
return RedirectToAction("MenuInicial", "Menu", new { area = "Configuration" });
}
}
else
{
ModelState.AddModelError("", "The user name or password provided is incorrect.");
}
It runs ok at developing time but after publish the site doesn't work.
My first link (It shows a welcome and provide a logon Button)
[http://localhost/mobile1]
After clicking on logonButton:
[http://localhost/mobile1#/Mobile1/Account/LogOn]
After type user and password it say
Error loading page
if manullay change the link
[http://localhost/mobile1#/Mobile1/Account/LogOn] to [localhost/mobile1/Account/LogOn]
The same error happen.
Very tks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个安全问题,操作结果需要写入一些文件。
通过模拟某些 Windows 有效用户的上下文,对需要写入文件的文件夹具有正确的权限,解决了这个问题。
在 web.config 的 system.web 部分添加
This was a security issue, the actionresult need to write some files..
It was solved impersonatting the context to some windows valid user with the right permissions to the folder where the files need to write.
at the web.config in the section system.web add