Hi,
I created a Login view in mvc3 application.
I have the following code to call the authentication function:
$('#btnLogin').click(function () {
var user = $('#txtUserName').val();
var pass = $('#txtPass').val();
$.ajax({
url: '/Login/Login_btnClick',
type: 'POST',
data: { userName: user, password: pass },
success: function (result) {
if (result == false) {
alert('Invalid Username or Password');
}
},
error: function (result) {
alert(result.responseText);
}
})
});
As I set the web.config to use Form Authentication:
<authentication mode="Forms">
<forms loginUrl="~/Login/Login" defaultUrl="~/Home/index" />
</authentication>
<authorization>
<deny users="?" />
</authorization>
I also added some locations to be available for all users:
<location path="Content">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
<location path="Scripts">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
Then I tried to login using me Login View, but my application couldn't load my functions. Using chrome I saw the following error:
Failed to load resource: the server responded with a status of 400 (Bad Request) http://localhost/ReplaceDNN/Login/%3C%=%20Url.Content
I thought it might be because it can't reach my controller's code since the user is not authenticated yet, so I added to the web.config:
<location path="Controllers">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
It still didn't work...
I also tried on my form to do the following:
<form method="post" action="/Login/Login_btnClick">
<div align="center">
<table border="border: solid 1px #e8eef4;">
<tr>
<td style="background-color: #e6e6fa">
<h2 align="center">
Login</h2>
<table>
<tr>
<td>
<label style="color: Black; font-weight: bold">
User Name:</label>
</td>
<td>
@Html.TextBox("txtUserName")
</td>
</tr>
<tr>
<td>
<label style="color: Black; font-weight: bold">
Password:</label>
</td>
<td>
@Html.TextBox("txtPass")
</td>
</tr>
</table>
<br />
@*<button id="btnLogin" style="width: 100px">
Login</button>*@
<input type="submit" name="Login" value="Login" />
</td>
</tr>
</table>
</div>
</form>
As I figured it, it supposed on submit to get to the function in the "action" of the form. It still doesn't work. same error....
Any idea what can I do in order to solve it?
Thanks