asp.net-mvc – FormsAuthentication.RedirectFromLoginPage()如
发布时间:2020-12-16 04:08:12 所属栏目:asp.Net 来源:网络整理
导读:它不会返回视图.事实上,Action在调用之后仍然需要返回一个视图……那么发生了什么? 解决方法 如果要使用FormsAuthentication系统,则需要切换到此行(隐式使用returnUrl参数). return Redirect(FormsAuthentication.GetRedirectUrl(model.UserName,true)); 您
它不会返回视图.事实上,Action在调用之后仍然需要返回一个视图……那么发生了什么?
解决方法
如果要使用FormsAuthentication系统,则需要切换到此行(隐式使用returnUrl参数).
return Redirect(FormsAuthentication.GetRedirectUrl(model.UserName,true)); 您将获得FormsAuthentication.RedirectFromLoginPage将使用的URL,但您将使用RedirectResult明确地从操作方法中保释. 注意 如果你走这条路线,你会想要在表单auth web.config行中放置一个defaultUrl参数,以防有人直接进入你的登录页面(或者他们传入一个不通过FormsAuthentication安全限制的redirectUrl).如果不覆盖默认值,错误的URL将被重定向到?/ default.aspx.在大多数MVC应用程序中,这可能是404. <forms loginUrl="~/Account/LogOn" defaultUrl="~/" timeout="2880"> 替代 如果您启动一个新的MVC 3示例“Internet应用程序”,您将找到一个LogOn操作方法,该方法处理类似于FormsAuthentication.RedirectFromLoginPage内部执行的returnUrl. if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/")) { return Redirect(returnUrl); } else { return RedirectToAction("Index","Home"); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- .NET Core技术研究-主机Host ASP.NET Core技术研
- 如何在asp.net页面上的<%...%>标签内使用c#代码?
- asp.net-mvc – 模型本身应该进行一些计算吗?
- asp.net – 无Cookie属性web.config
- 在ASP.NET中的Response.Redirect中传递cookie
- 回发后的ASP.Net无法找到指定的URL
- asp.net-mvc – 使用ASP.NET MVC,有没有办法捕获所有POST请
- asp.net – 形式auth超时和会话超时的差异
- asp.net mvc c#tooltip
- asp.net – 有没有办法使用System.Net.Mail.SendAsync()捕获
推荐文章
站长推荐
- asp.net – 抛出类型“System.OutOfMemoryExcept
- asp.net-core – options的用途.AutomaticAuthen
- asp.net-mvc – 是否有任何基于ASP.NET MVC订阅的
- 高级ASP.NET主机
- entity-framework – 如何在ASP.NET MVC 5中为同
- asp.net-mvc-4 – DataAnnotation的必需属性
- 实体框架 – WebApi OData:$filter’any’或’a
- asp.net – 由于其保护级别,未声明变量可能无法访
- asp.net – 自动将视频格式转换为Flash Video
- asp.net-mvc – 迷你探查器不显示ajax请求信息?
热点阅读