I have created an web application with MVC template.I have created a custom view -Login.cshtml .

Login.cshtml(View)

       @using(Html.BeginForm())
      {
        <div id="Email">
            @Html.Label("UserName")
            @Html.TextBox("user")
        </div>
        <div id="Password">
            @Html.Label("Password")
            @Html.TextBox("password")
        </div>
        <input id="LoginBtn" type="submit" value="Login" />
      }

In my controller method if i use [authorize] attribute,it takes me to /Accounts/Login by default which is already available in the template.

MyController(Controller)

    [Authorize]
    public ActionResult Start()
    {
       return View();
    }

I need the authentication view as Login.cshtml. So, I tried adding the forms authentication in Configuration file (web.config)

Web.Config

<authentication mode="Forms">
  <forms name="xyz" loginUrl="http://localhost:2680/My/Login">
    <credentials>
      <user name="abc" password="pass123" />
    </credentials> 
  </forms>
</authentication>

Even after adding it , the Accounts/Login ran instead of My/login.

So my question is how to use a custom view for login when we specify [authorize] attribute in controller methods?

Related posts

Recent Viewed