asp.net mvc - Right way to Redirect a URL segment to MVC Controller -


i have existing controller

public class homecontroller : controller {       public actionresult index()     {         return redirect("/scorecard");      }      [outputcache(duration = 18000)]     public actionresult scorecard()     {         return view();     } } 

this maps http://siteurl/home/scorecard . wanted segment http://siteurl/scorecard redirect controller action . best wayt . tried checking requesturl in session_start in global.aspx redirects dont seem happening . other alternative thought of using different controller "scorecardcontroller" , having redirecttoaction("scorecard","home") in index view there.

you add filteraccess class on app_start folder this:

public class filteracess : actionfilterattribute {    public override void onactionexecuting(actionexecutingcontext context)    {        //redirect        if (httpcontext.current.request.url=="http://siteurl/scorecard"){              context.httpcontext.response.redirect("~/home/scorecard");         }   } } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -