我正在制作一个新的(空模板)ASP.NET MVC 5应用程序,我无法注销这个应用程序.我的注销行动:
public ActionResult LogOff()
{
if (User.Identity.IsAuthenticated)
{
//break here
}
try
{
AuthenticationManager.SignOut();
if (User.Identity.IsAuthenticated || Request.IsAuthenticated)
{
//break here;
}
}
return RedirectToAction("Login", "Account");
}
Run Code Online (Sandbox Code Playgroud)
启动课程:
public partial class Startup
{
public void ConfigureAuth(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login")
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
}
}
Run Code Online (Sandbox Code Playgroud)
应用背景:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", false)
{
}
}
Run Code Online (Sandbox Code Playgroud)
连接字符串:
<connectionStrings>
<add name="DefaultConnection" connectionString="Server=.;Database=DataTest;Trusted_Connection=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
操作LogOff()执行没有问题,并将我重定向到"登录"操作,但我仍然登录.它有什么问题?
我正在考虑使用哈希方法为Asp.Net MVC中的ajax调用管理的内容创建静态URL.我正在处理的概念证明是一个个人资料页面/user/profile
,人们可以浏览和编辑不同的部分.您可以随时要求以下网址/user/profile#password
直接访问您的个人资料页面,在更改密码部分
但是,我想知道我是不是以不好的方式开始这个,因为显然我无法以任何方式访问哈希之后的部分,除非通过声明哈希的路由值global.asax
.所以我想知道这是否是访问这部分网址的正确方法?
我应该声明一个路由值,还是有另一种方法来处理哈希值(框架,javascript或mvc)?
编辑添加:
在纯JavaScript中,我没有使用该window.location.hash
属性的问题,我不确定它在今天的浏览器中是多么标准,因此关于将使用它的javascript框架/插件的问题.
我的问题非常直截了当......
我有一个Action
接受两个HttpGet
和HttpPost
,但我想ValidateAntiForgeryToken
在http请求时设置属性POST
,而不是HttpGet
.
我可以找到请求是在操作中GET
还是POST
在操作中,但我需要在调用操作之前知道.
[ValidateAntiForgeryToken] // Only for HttpPost
public ActionResult Index() // Allows HttpPost / HttpGet
{
}
Run Code Online (Sandbox Code Playgroud)
有没有可能实现这一点而不重复行动?
谢谢