3

Sometimes my application generates URLs that look like http://localhost/?Area= or http://localhost/SomeController?Area=

I don't currently have any areas defined in this project, and I have tried removing area registration from application startup.

The only answer I have found is to use <a href="Url.Action()"> URLs.

There must be a cleaner way of removing this. Manually removing this from the URLs seems to provide the exact same result, but I am unsure as to why this is coming up in the the first place.

How do I resolve this using the routing system? please note that i am using t4mvc to generate actionlinks not the default mvc actionlink helpers

Edit:

public class MvcApplication : System.Web.HttpApplication
{
    public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    {
        filters.Add(new HandleErrorAttribute());
    }



    /// <summary>
    /// Registers MVC Routing Collection.
    /// </summary>
    /// <param name="routes">The routes.</param>
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");




        routes.MapRoute(
            "secstdsrte",
            "SecondaryStandards/{standardType}/{sampleid}",
            MVC.Reports.SecondaryStandards(),
            null,
            new { standardType = new SecondaryStandardTypeConstraint()

            }
        );


        routes.MapRoute(
            "misaRoute",
            "Misa",
            MVC.Reports.MISA()
            );

        routes.MapRoute(
            "outfallroute",
            "Outfalls/{fromDate}/{toDate}",
            MVC.Reports.Outfalls( ApplicationController.DefaultFromDate, ApplicationController.DefaultToDate),
            null,
            new 
            { 
                fromDate = new DateTimeConstraint(), 
                toDate = new DateTimeConstraint()
            }
        );

        routes.MapRoute(
            "offspecRoute",
            "Offspec/{fromDate}/{toDate}",
            MVC.Reports.OleOffspec(ApplicationController.DefaultFromDate, ApplicationController.DefaultToDate),
            null,
            new //route constraints 
            {
                fromDate = new DateTimeConstraint(),
                toDate = new DateTimeConstraint()
            }
        );

        routes.MapRoute(
            "searchRoute",
            "Search",
            MVC.Reports.Search()

        );





        routes.MapRoute(
        "compareresultsroute",
        "compare/{samplePoint}/{analysis}/{fromDate}/{toDate}",
        MVC.Reports.CompareResults(null, null, null, ApplicationController.DefaultFromDate, ApplicationController.DefaultToDate),
        null,
        new
        {
            samplePoint = new SamplePointExistsConstraint(),
            analysis = new AnalysisExistsConstraint(),
            fromDate = new DateTimeConstraint(),
            toDate = new DateTimeConstraint() 
        }

        );

        routes.MapRoute(
        "reportsRoute",
        "Reports/{samplePoint}/{fromDate}/{toDate}",
        MVC.Reports.Results("", ApplicationController.DefaultFromDate, ApplicationController.DefaultToDate),
        null,
        new //route constraints 
        {
            samplePoint = new SamplePointExistsConstraint(),
            fromDate = new DateTimeConstraint(),
            toDate = new DateTimeConstraint() }
        );

        routes.MapRoute(
            "railcarsRoute",
            "RailCars/{forDate}",
            MVC.Reports.RailCars(ApplicationController.DefaultToDate),
            null,
            new { forDate = new DateTimeConstraint() }
        );

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new
            { controller = "Reports", action = "Index", id =UrlParameter.Optional } // Parameter defaults
        );
    }
    /// <summary>
    /// Returns boolean value indicating whether the application is currently in debug mode 
    /// </summary>
    public static bool isDebugging
    {
        get
        {
            return HttpContext.Current != null && HttpContext.Current.IsDebuggingEnabled;
        }
    }




    protected void Application_Start()
    {

        AreaRegistration.RegisterAllAreas();

        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterRoutes(RouteTable.Routes);
    }
}
Chris McGrath
  • 1,727
  • 3
  • 19
  • 45
  • 2
    What are you using to generate the URLs? I've never seen the standard URL helpers append an Area= to a URL. Even if you were using Areas, you still wouldn't get URLs like that. Areas tend to be of the form /localhost/area/controller/action – mfanto Mar 01 '12 at 20:50
  • 3
    Can you post your route table and the code you use to generate the urls? – bhamlin Mar 01 '12 at 21:16

2 Answers2

1

You are more than likely ending up calling the wrong overload of ActionLink. There's an overload that takes a RouteValueDictionary and people confuse it for html attributes (it looks similar).

@Html.ActionLink("Link", "Action", "Controller", new { id = 1 }, new { @css="myclass" })

if you're not specifying a route value, then use null.

@Html.ActionLink("Link", "Action", "Controller", null, new { @css="myclass" })
Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
  • im using t4mvc links with action helpers but ill take a closer look at it – Chris McGrath Mar 02 '12 at 13:05
  • using the standard action link helpers fixes the problem but still happens while using t4mvc links is this a bug in t4mvc not properly setting the area or an issue with how it is defined in routing – Chris McGrath Mar 13 '12 at 00:39
1

This issue was previously discussed on T4MVC @Url.Action(MVC.Controller.Action()) Renders "?Area=" Parameter in QueryString.

In short, it's a bug in T4MVC when the site doesn't use areas. You can work around by deleting this line (around line 303):

result.RouteValueDictionary.Add("Area", area ?? "");
Community
  • 1
  • 1
David Ebbo
  • 42,443
  • 8
  • 103
  • 117