我有一个页面,当你按"注销"它会重定向到login.aspx有一个Page_Load方法调用的页面FormsAuthentication.SignOut().
母版页会显示在屏幕的右上角的"注销"链接并显示它的条件Page.User.Identity.IsAuthenticated是true.然而,通过单步执行代码后,该signout方法不会自动设置IsAuthenticated到false这是相当恼人的,任何想法?
在SignOut()调用之后使用此方法重定向到'... login.aspx?ReturnUrl =%2fmydomainname%2flogout.aspx',以便用户无法再次重新登录,因为成功登录将返回到注销页面.登录页面在webconfig中设置,应用程序成功获取该页面.为什么ReturnURL会卡在URL的尾部?
我是一名新开发人员,我被分配了解决我们的注销功能无法正常工作的任务.我已经尝试了所有可以找到的方法.下面是我保留的日志,其中包括我使用过的方法.
在CommonHeader.ascx表单中添加了一个注销按钮
已经在logout.aspx.vb表单中尝试了许多方法来使其结束或清除会话,但它们都不起作用.
一个.logout.aspx.vb形式中定义的ClearSession子例程:
Session("Variable") = ""
FormsAuthentication.SignOut()
Session.RemoveAll()
Session.Abandon()
Session.Clear()
Run Code Online (Sandbox Code Playgroud)
湾 还将其添加到Page_Load子例程的顶部:
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache)
HttpContext.Current.Response.Cache.SetNoServerCaching()
HttpContext.Current.Response.Cache.SetNoStore()
Run Code Online (Sandbox Code Playgroud)
C.还将ClearSession子例程更改Session.Contents.Remove("Variable")为Session("Variable") = ""
这些方法都不起作用.我们使用Siteminder,我一直想知道这是否是问题的根源.我在清除使用Siteminder的会话时找不到任何内容.另请注意,此应用程序使用Visual Studio 2003编码.
这是我在ascx文件中使用的按钮的代码:
athp:TopNavText Title ="Log Out"NavigateUrl ="logout.aspx"Target ="_ top"/
然后在"logout.aspx"表单上,我尝试使用上述方法之一或每种方法的组合.这是我触摸它之前的代码:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ClearSession()
Response.Redirect("login.aspx")
End Sub
Public Sub ClearSession()
Session("Variable") = ""
End Sub
Run Code Online (Sandbox Code Playgroud) 我正在开发一个带有安全部分的网站,即名为"PIP"的文件夹.
登录部分工作正常,但是当我单击注销时,用户仍然是已知的,并且如果他/她触摸安全部分,则不会被重定向到登录页面.
这是我的web.config:
<system.web>
<authentication mode="Forms">
<forms loginUrl="Login.aspx" name=".ASPXFORMSAUTH">
</forms>
</authentication>
</system.web>
<location path="PIP">
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>
Run Code Online (Sandbox Code Playgroud)
用户通过身份验证的登录页面:
FormsAuthentication.RedirectFromLoginPage(uid, false);
Run Code Online (Sandbox Code Playgroud)
在安全文件夹(PIP)的default.aspx页面上有一个注销按钮,该按钮后面的代码:
FormsAuthentication.SignOut();
Response.Redirect("~/Default.aspx", true);
Run Code Online (Sandbox Code Playgroud)
在页面"Default.aspx"是一个链接到〜/ PIP/Default.aspx,它应该被重定向到登录页面但不是.注意会议似乎不会受到退出的影响.
我尝试了很多选项,手动删除会话.Session.Clear,Session.Abandon但似乎没有任何效果.
我希望你们能指出我正确的方向!
提前致谢.
我有一个asp.net网络表单。用户进行身份验证时,它将创建一个名为.aspxauth的安全cookie。
uppon注销,我称之为这两种方法
FormsAuthentication.SignOut();
Session.Abandon()
Run Code Online (Sandbox Code Playgroud)
问题是我们进行了渗透测试,如果我窃取了cookie,注销并手动重新插入cookie,我将再次被登录。因此,.aspauth不会使服务器端无效。
我已经用谷歌搜索了,但是找不到该安全漏洞的答案。
这是我的代码登录
var expire = DateTime.Now.AddDays(7);
// Create a new ticket used for authentication
var ticket = new FormsAuthenticationTicket(
1, // Ticket version
username, // Username to be associated with this ticket
DateTime.Now, // Date/time issued
expire, // Date/time to expire
true, // "true" for a persistent user cookie (could be a checkbox on form)
roles, // User-data (the roles from this user record in our database)
FormsAuthentication.FormsCookiePath); // Path cookie is valid for
// Hash the cookie for transport over …Run Code Online (Sandbox Code Playgroud) 我试图在ASP.NET MVC中实现Logout功能.
我为我的项目使用Forms身份验证.
这是我的退出代码:
FormsAuthentication.SignOut();
Response.Cookies.Clear();
FormsAuthenticationTicket ticket =
new FormsAuthenticationTicket(
1,
FormsAuthentication.FormsCookieName,
DateTime.Today.AddYears(-1),
DateTime.Today.AddYears(-2),
true,
string.Empty);
Response.Cookies[FormsAuthentication.FormsCookieName].Value =
FormsAuthentication.Encrypt(ticket);
Response.Cookies[FormsAuthentication.FormsCookieName].Expires =
DateTime.Today.AddYears(-2);
return Redirect("LogOn");
Run Code Online (Sandbox Code Playgroud)
此代码将用户重定向到登录屏幕.但是,如果我通过在地址栏中指定名称来调用操作方法(或从地址栏下拉列表中选择上一个链接),我仍然可以在不登录的情况下访问安全页面.
有人可以帮我解决这个问题吗?
我正在使用C#开发asp.NET 4.0 Web应用程序.我目前使用会话进行身份验证,在注销时我正在清除会话.但是当用户按下时会出现问题,他仍然可以看到缓存的页面.我想禁用这些页面的缓存,或确保检查它.
这样做的最佳方式是什么?如果我将服务器设置为不存储缓存信息,这会影响所有应用程序还是仅仅是我的应用程序?
我有一个带有 OAuth 登录配置的 WebAPI,如下所示:
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = authority,
PostLogoutRedirectUri = "https://www.microsoft.com/",
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthenticationFailed = context =>
{
context.HandleResponse();
context.Response.Redirect("/Error?message=" + context.Exception.Message);
return Task.FromResult(0);
}
}
});
Run Code Online (Sandbox Code Playgroud)
并强制所有控制器使用登录
config.Filters.Add(new System.Web.Http.AuthorizeAttribute());
Run Code Online (Sandbox Code Playgroud)
我现在想添加一个名为 LogoutController 的 ApiController(猜猜它是做什么的)。
我发现我可以使用以下方式从 MVC 注销
System.Web.Security.FormsAuthentication.SignOut();
Run Code Online (Sandbox Code Playgroud)
但我没有以这种方式从 WebAPI 注销。我没有找到任何如何从 WebAPI 注销的信息。但我发现注销过程中可能存在错误,cookie 被保留并必须手动删除,但是代码又是 MVC,似乎我无法进入HttpCookie我的HttpResponseMessage对象:
[HttpGet]
public HttpResponseMessage Logout()
{
FormsAuthentication.SignOut();
// clear authentication cookie
HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, "");
cookie1.Expires = DateTime.Now.AddYears(-1); …Run Code Online (Sandbox Code Playgroud) c# ×7
asp.net ×6
.net ×2
asp.net-mvc ×2
cookies ×1
httpcontext ×1
httphandler ×1
logout ×1
oauth-2.0 ×1
security ×1
session ×1
siteminder ×1