0

I use the default LogOn model of MVC3. LogOn partial view is in Layout view.

@Html.Partial( "~/Views/Home/LogOn.cshtml", new MyProject.Models.LogOnModel() ) 

After log on, Url is:

http://localhost:20234/?UserName=TestUsername&Password=121212&RememberMe=True

I dont want the password seen in the URL. How do I remove the password (also Username, RememberMe) from the URL?

2 Answers 2

2

When you transfer data to server with GET method then parameters are visible in url. You should use POST method in this case. For example:

<form action="/Account/Logon" method="POST">
    <input type="text" name="Username"/>
    <input type="text" name="Password"/>
    <input type="submit"/>
</form>
Sign up to request clarification or add additional context in comments.

4 Comments

I wrote : @using ( Html.BeginForm( "LogOn", "Home", FormMethod.Post )) {....} in LogOn partial view
Yes, that will render as: <form action="/Home/LogOn" method="POST">...</form> Now you should post a form and that's it.
You are posting with <input type=submit/> ? you should not use <a href="..."></a> to post a form.
I am posting with <input type=submit/>
1

1)Pease change to your default route:

 routes.MapRoute(
                    "DefaultSite",
                    "{controller}/{action}/{id}",
                    new
                        { 
                            controller ="Account",
                            action ="LogOn",
                            id = UrlParameter.Optional
                        }
                    );

2)Load partial on Master Load file:

 @using (Html.BeginForm("LogOn","Account",HttpMethod.Post))
    {
        @Html.AntiForgeryToken() 
        @Html.Partial( "~/Views/Home/LogOn.cshtml", new MyProject.Models.LogOnModel())          
    }

3)And Account contrroller in added your logon logice:

  [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Login(LogOnModel model)
        {
            if (ModelState.IsValid)
            {
                //TODO:

                return RedirectToAction("index", "home");
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", @"The user name or password provided is incorrect.");
            return View(model);
        }

1 Comment

LogOn is partial view in my application and place in Home view.

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.