0

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.

1 Answer 1

1

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
}
Sign up to request clarification or add additional context in comments.

4 Comments

I have even tried with a different controller (welcome) and it did not work
With the above route, I get the URL as www.example.com/account/logon?returnurl=login
@saravanan did you change web.config as in step 2? It seems you didn't
I have checked with a WelcomeController and the following web.config <forms loginUrl="/Welcome" cookieless="UseCookies" name="FormAuthentication" /> and in global.asax.cs file, I have added as follows routes.MapRoute("Default","Welcome",new { controller = "Account", action = "LogOn", id = "" }); and it works like http://www.example.com/Welcome.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.