0

I want to use my own Login Page for authentication, but it is giving me this error

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Account/PasswordLock

Anyone knows why?Here is my code, I created a new page called PasswordLock.aspx with a login tool in it. everything works fine with the original Login form, but not mine own.

<authentication mode="Forms">
  <forms loginUrl="~/Account/PasswordLock" timeout="2880" />
</authentication>

while this will work fine

<authentication mode="Forms">
  <forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>

Thanks

4
  • Do you have a PasswordLock action defined? Is it decorated with AllowAnonymous? You need an action in MVC not just a view. Commented Jul 23, 2013 at 13:58
  • @BradChristie Sorry Brad, i am new to MVC, can you please explain abit more? thanks Commented Jul 23, 2013 at 14:00
  • 1
    @yzwboy Routing and Controller actions are the fundamental part of ASP.NET MVC. You should really understand those before you try to write anything. The tutorials at asp.net/mvc are a good start. Commented Jul 23, 2013 at 14:02
  • @cadrell0 Thank you, yea i was rushing it...i kinda have an idea of its structure in mind but never actually worked with it, i got it now, thanks again Commented Jul 23, 2013 at 14:56

1 Answer 1

1

In ASP.NET MVC, your URLs don't map to files; they map to actions. So, having a file at ~/Accounts/PasswordLock.aspx doesn't help. What you need is a route for that URL. The routes are usually set up in a file called RouteConfig, under the App_Start folder, executed by the Application_Start() method in Global.asax. The usual default route looks like this:

routes.MapRoute(
    name: "default",
    routeTemplate: "{controller}/{action}/{id}",
    defaults: new { id = RouteParameter.Optional });

This means that a URL that goes www.example.com/Accounts/PasswordLock will map to a controller called AccountsController, and a method on that controller called PasswordLock. This method should return a View which by default will be called PasswordLock.cshtml. Note that the new Razor v2 view engine uses .cshtml files rather than .aspx.

This is all pretty fundamental to ASP.NET MVC programming; it sounds rather like you're jumping in blindly. I'd strongly advise reading the tutorials at www.asp.net/mvc, particularly the ones on controllers and routing.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you guys for the help, after some more research and experimenting, i got the view part to work, but is there a tool like the login tool in .aspx for razor cshtml? or do you have to set up custom views yourself by coding?
You pretty much have to build it. MVC puts pretty much nothing between the programmer and the actual HTML, so for a login page you'll be building a form to carry out a standard HTTP POST action to submit the various values, and then you'll need a method on the server to receive that and do your logic for working out whether they're allowed in.

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.