0

我正在尝试使用确认电子邮件设置会员提供商。User使用 memb 成功注册。提供者。

注册后,将发送一封确认电子邮件userProviderKey,用于批准用户。链接发送如下

http://localhost:48992/Account/Verify/e37df60d-b436-4b19-ac73-4343272e10e8

用户必须单击使用密钥 (providerUserKey) 发送的链接,问题是该密钥在调试模式下甚至不显示为参数

// in debug providerUserKey is null
public ActionResult Verify(string providerUserKey)
{    
}

可能是什么问题?

4

4 回答 4

1

除非您在全局 asax 中指定了规则,否则您的 url 应该看起来像

http://localhost:48992/Account/Verify?providerUserKey=e37df60d-b436-4b19-ac73-4343272e10e8

如果您想使用上述格式,您需要在 global.asax 中映射一条新路线

routes.MapRoute(
    // Route name
    "routename",
    // Url with parameters
    "Account/Verify/{providerUserKey}/",
    // Parameter defaults
    new { controller = "Account", action = "Verify" }
    );
于 2013-02-14T12:17:50.337 回答
1

尝试将查询更改为

http://localhost:48992/Account/Verify?providerUserKey=e37df60d-b436-4b19-ac73-4343272e10e8

ActionResult正在寻找此参数URL

于 2013-02-14T12:18:08.183 回答
1

默认 MVC 路由是 {Controller}/{Action}/{Id} 因此,如果参数名称是 Id,它会识别它...

将其更改为以下,它将起作用。

public ActionResult Verify(string id)
        {    
        }

不过,如果您不想更改参数名称,那么您可以在 global.asax 文件中添加以下路由,它将正常工作。

routes.MapRoute("MyRouteName","{Controller}/{action}/{providerUserKey}")

如果需要,您还可以将默认值传递给它,因为您的路径是预定义的。干杯

于 2013-02-14T12:22:11.397 回答
1

如果您将 Global.asax.cs 文件的路由配置为:

          routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional });

您可以看到它的id参数是可选的。因此,如果查询字符串被识别为,id那么它将具有您传递的值。

更改为id以便providerUserKey为您完成工作。

      routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{providerUserKey}", // URL with parameters
            new { controller = "Home", action = "Index",providerUserKey=UrlParameter.Optional });

或将默认可选参数保留为并作为附加查询字符串参数id传递。providerUserKey

像这样说:

     @Html.Action("","",new { providerUserKey="e37df60d-b436-" })

希望能帮助到你

于 2013-02-14T12:25:12.460 回答