0

I am currently writing an Authorisation filter in MVC4, it has the default URL rewrite

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

And with the above route I have a custom authorise attribute which starts like this

protected override bool AuthorizeCore(HttpContextBase httpContext)
{
    String Value = httpContext.Request["id"];

however the id isn't coming through.

When I take the route away above it does.

Is there anyway I can have the route AND the id in the authorise attribute?

4

1 に答える 1

1

私のソリューションに興味のある人のために、RequestContextのRouteDataから必要な情報を取得することができました-

    protected override bool AuthorizeCore(HttpContextBase httpContext)
    {
        String Value = httpContext.Request["id"];
        if(String.IsNullOrWhiteSpace(Value))
            Value = httpContext.Request.RequestContext.RouteData.Values["id"] as String;
于 2013-01-17T22:16:11.207 に答える