Routing is used to create custom routing. Custom routing like url of as we want.
Here I am talking about Redirection of website along with some string in its URL.
I have a website like mydomain.com and i would like to redirect it in mydomain.com/abc or /mystring url.
This can easliy done with Custom routing in route.config file in MVC like
routes.MapRoute(
name: "Default",
url: "mystring/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
The above syntax for routing is creating route as -
mydomain.com/mystring
now if we try mydomain.com then server will not found index url and will throw mydomain.com redirected you too many times error.
The second main thing is add a httpRedirect tag either in IIS setting or in web.config file. If in IIS httpRedirect tag is not available then go to IIS setting and enable it.
Now need to change in web.config file in <system.webServer> tag and add below syntax.
<httpRedirect childOnly="true" destination="/mystring" enabled="true"></httpRedirect>
ChildOnly attribute should be true. In destination need to provide the string which we want to redirect.
Now the site will redirect automatically from mydomain.com to mydomain.com/mystring.
No comments:
Post a Comment