Bla*_*man 0 c# asp.net asp.net-mvc forms-authentication
我正在使用ASP.NET MVC,我正在做的登录操作:
[AcceptVerbs("POST")]
public ActionResult Login(FormCollection form)
{
User validatedUser = // tests username/pwd here.
FormsAuthentication.RedirectFromLoginPage(
validatedUser.ID.ToString(), rememberMe);
if(String.IsNullOrEmpty(Request["ReturnUrl"]))
string redirectUrl = Request["ReturnUrl"];
if (!String.IsNullOrEmpty(Request.QueryString["ReturnUrl"]))
string redirectUrl = Request["ReturnUrl"];
}
Run Code Online (Sandbox Code Playgroud)
当我在登录页面时,我的网址看起来像这样:
http://localhost:56112/user/login?ReturnUrl=/admin/settings
Run Code Online (Sandbox Code Playgroud)
这里有什么不妥吗?
我的web.config:
<authentication mode="Forms">
<forms loginUrl="/user/login"
protection="All"
timeout="30"
name="SomeCookie"
requireSSL="false"
slidingExpiration="true"
defaultUrl="default.aspx" />
Run Code Online (Sandbox Code Playgroud)
我建议你不要RedirectFromLoginPage在MVC应用程序中使用方法.使用标准ASP.NET MVC技术执行重定向会更好.您可以使用SetAuthCookie方法:
public ActionResult Login(FormCollection form)
{
// ...
FormsAuthentication.SetAuthCookie(validatedUser.ID.ToString(), rememberMe);
// ...
return Redirect(FormsAuthentication.DefaultUrl); // will read default url from web.config
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
965 次 |
| 最近记录: |