我如何使用在asp.net MVC Server.Transfer方法? [英] How do I use Server.Transfer method in asp.net MVC?

查看:88
本文介绍了我如何使用在asp.net MVC Server.Transfer方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用它的登录页面。

if (Session["UserID"] == null)
     Server.Transfer("/Account/Login", true);

但我得到的异常 - >错误执行子请求/帐号/登录

But I get The Exception -> Error executing child request /Account/Login.

推荐答案

要使用服务器传送方式你可以看看<一个href=\"http://stackoverflow.com/questions/799511/how-to-simulate-server-transfer-in-asp-net-mvc/1242525#1242525\">this从西蒙·韦弗,但在你的问题的情况下,我会用一个重定向操作来代替。

To use a server transfer method you could look at this from Simon Weaver, but in the context of your question I would use a redirect action instead.

RedirectToAction(new {
   controller="Account", 
   action="Login"
});

要得到它告诉登录控制器哪里去回试

to get it to tell the login controller where to go back to try

RedirectToAction( new {
   controller="Account",
   action="Login",
   new RouteValueDictionary { 
      {"actionToGoBackTo", "theActionName"},
      {"controllerToGoBackTo", "theControllerName"}
   }); 

请注意,该登录操作将需要采取两个字符串参数,actionToGoBackTo和controllerToGoBackTo。

note that the Login action will need to take two string arguments, actionToGoBackTo, and controllerToGoBackTo.

这篇关于我如何使用在asp.net MVC Server.Transfer方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆