RedirectToAction在运行时

时间:2012-02-24 18:28:20

标签: asp.net-mvc-3 model-view-controller redirecttoaction

我正在开发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://本地主机/ mobile1]

点击logonButton后: [HTTP://本地主机/ mobile1#/ Mobile1 /帐户/ LogOn支持]

输入用户名和密码后说出来 加载页面时出错

如果manullay更改了链接

[http:// localhost / mobile1#/ Mobile1 / Account / LogOn]到[localhost / mobile1 / Account / LogOn] 发生同样的错误。

非常感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

这是一个安全问题,actionresult需要写一些文件..

解决了对某些Windows有效用户模仿上下文的问题,并对文件需要写入的文件夹具有正确的权限。

在system.web添加

部分的web.config中
<system.web>
    .... 
    <identity impersonate="true"
          userName="username"
          password="userpassword"/>        
</system.web>
相关问题