处理ASP.Net MVC5路由中的“额外”参数

时间:2015-10-27 20:43:04

标签: c# asp.net-mvc

我有这条路需要处理:

http://mpdev.website.com/Account/ExternalLogOn?LogonTicket=c3792319c8711a0dd465bbd6f6b31ea913b42db7&PID=1137565&ReturnUrl=/Home/CompReq?EC=151120TXAM

帐户控制器中的ExternalLogon操作会根据LogonTicket和PID之间的检查自动记录用户。然后它应该重定向到ReturnUrl。

如何修复/ Home / CompReq路由以处理EC参数以及如何修改Home Controller中的Action?

我的RouteConfig中只有一条路线:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
}

此链接完美无缺,但我知道我没有任何参数。

http://mpdev.website.com/Account/ExternalLogOn?LogonTicket=c3792319c8711a0dd465bbd6f6b31ea913b42db7&PID=1137565&ReturnUrl=/Home/MyInfo

Home Controller Action定义如下:

public ActionResult CompReq(string eventcode)

ExternalLogon定义:

ExternalLogOn(string LogonTicket, int? PID, string User, string EC, String State, string ReturnUrl)

1 个答案:

答案 0 :(得分:1)

ReturnUrl值应该是url编码的:

http://mpdev.website.com/Account/ExternalLogOn?LogonTicket=c3792319c8711a0dd465bbd6f6b31ea913b42db7&PID=1137565&ReturnUrl=%2FHome%2FCompReq%3FEC%3D151120TXAM

CompReq操作应具有与查询参数名称相同的函数参数名称:

public ActionResult CompReq(string EC)

ExternalLogon操作应该有适当的参数:

ExternalLogOn(string LogonTicket, int? PID, string ReturnUrl)

在ExternalLogOn中,您重定向到ReturnUrl参数:

return Redirect(ReturnUrl);