Saravanan
Saravanan

Reputation: 7854

Hiding the Default form authentication url in asp.net mvc

I have an application which is configured to use

~/Account/LogOn

in the

web.config

file for the authentication.

I would like to have the URL just point to www.example.com instead of www.example.com/Account/LogOn.

I have tried to have the routing configuration as follows, but it does not work

routes.MapRoute(
            "Default",                                              // Route name
            "{controller}/{action}/{id}",                           // URL with parameters
            new { controller = "Account", action = "LogOn", id = "" }
        );

Kindly suggest the right practice that can be used. I tried to remove the loginurl from web.config file but it is not of use and shows authorization error while running.

Upvotes: 0

Views: 437

Answers (1)

Andrey Gubal
Andrey Gubal

Reputation: 3479

I'm not sure you may change routing to have the same address for two actions: Home/Index and Account/LogOn. But if you want change default logOn routing you need 2 steps:

1) Add one more routing:

//This route returns www.example.com/Login
routes.MapRoute(
            "MyRoute",                                             
            "Login",                           
            new { controller = "Account", action = "LogOn", id = "" }
        );

2) Make changes in web.config:

~/Login

In the same way you may create any other routing for LogOn

As for me the only solution to have login on Index page is to do like this (and delete redirect from web.config):

@if(!Request.IsAuthenticated)
{
   //PartialView with Log In form
}
else
{
 // Your Index page content
}

Upvotes: 1

Related Questions