C# 自定义用户身份验证
我想实现自定义用户身份验证。我有用户名文本框和密码文本框,还有提交表单的按钮C# 自定义用户身份验证,c#,asp.net-mvc,authentication,cookies,C#,Asp.net Mvc,Authentication,Cookies,我想实现自定义用户身份验证。我有用户名文本框和密码文本框,还有提交表单的按钮 @using (@Html.BeginForm("Submit","Profile")) { <table> <tr> <td>Username: </td> <td>@Html.TextBox("Username")</td> </tr>
@using (@Html.BeginForm("Submit","Profile"))
{
<table>
<tr>
<td>Username: </td>
<td>@Html.TextBox("Username")</td>
</tr>
<tr>
<td>Password: </td>
<td>@Html.TextBox("Password")</td>
</tr>
<tr>
<td></td>
<td><input id="btnSubmit" type="submit" value="Submit" /></td>
</tr>
</table>
}
我只想检查是否没有cookie,操作方法是否不可访问。如果有一个cookie可以访问。根据我的评论,类似这样的东西应该可以工作:
var cookie = Request.Cookie["myCookie"];
if (cookie == null)
return new HttpUnauthorizedResult();
为什么不使用FormsAuthentication.SetAuthCookie方法设置coockie和standart[Authorize]属性?检查请求中是否存在cookie,如果不存在,发送401响应?如何发送401响应?返回新的HttpUnauthorizedResult
var cookie = Request.Cookie["myCookie"];
if (cookie == null)
return new HttpUnauthorizedResult();