Asp.Net Routing - Display complete URL

后端 未结 3 744
臣服心动
臣服心动 2020-12-04 02:33

I have a domain \"http://www.abc.com\". I have deployed an ASP.net MVC4 app on this domain. I have also configured a default route in RouteConfig.cs as shown below



        
3条回答
  •  被撕碎了的回忆
    2020-12-04 02:45

    You'll need to do some kind of url rewriting. Probably the quickest way is to add a RewritePath call to your BeginRequest in Global.asax. In your case it'd be something like this:

    void Application_BeginRequest(Object sender, EventArgs e)
    {
        string originalPath = HttpContext.Current.Request.Path.ToLower();
        if (originalPath == "/") //Or whatever is equal to the blank path
            Context.RewritePath("/MyApp/Home");
    }   
    

    An improvement would be to dynamically pull the url from the route table for the replacement. Or you could use Microsoft URL Rewrite, but that's more complicated IMO.

提交回复
热议问题