我想实现这个功能,如用户已登录,系统将执行某种操作;如果用户没有登录,他将被引导到登录页面,在登录成功后返回我不知道下面的语句是否正确 protected void btnAddToFavorite_Click(object sender, EventArgs e)
{
if (HttpContext.Current.Request.IsAuthenticated)
{
//do something
}
else
{
Response.Redirect("~/Login.aspx?ReturnUrl=" + HttpUtility.UrlEncode(PublicPar.HTMLPathOfRoot + "ShowProject.aspx?Type=1&ID=2"));
}
}
{
if (HttpContext.Current.Request.IsAuthenticated)
{
//do something
}
else
{
Response.Redirect("~/Login.aspx?ReturnUrl=" + HttpUtility.UrlEncode(PublicPar.HTMLPathOfRoot + "ShowProject.aspx?Type=1&ID=2"));
}
}
解决方案 »
- 求比较好用的asp.net绘图控件,比如画柱形图,曲线图一类的
- Page.Header.Title = "标题";报错,怎么解决?
- 把查询结果保存本地,要有“打开保存取消”按钮。
- 我用ajax返回一个DataSet,请问如何在前台展示成Table ?
- 判断Session过期 问题!急
- 请教:GridView绑定后并设置了AutoGenerateEditButton="True" ,并出现了相应的编辑按钮。但是当点击编辑按钮却未能出现预料的编辑状态
- 两个表内容有一点关联。如果做级联更新?
- 一个简单问题:用户控件*.ascx怎么样控制位置,为什么老是在左上方,谢谢
- gridview问题
- 关于datalist模版的问题
- 内容页中使用UpdatePanel问题
- 怎么把gridview等数据源控件样式变好看
if(Session["user"]==null)
{}
forms验证
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
HttpApplication app = (HttpApplication) sender;
HttpContext ctx = app.Context ;
if (ctx.User != null)
{
if (ctx.Request.IsAuthenticated == true)
{
System.Web.Security.FormsIdentity fi = (System.Web.Security.FormsIdentity)ctx.User.Identity ;
System.Web.Security.FormsAuthenticationTicket ticket = fi.Ticket ;
string userData = ticket.UserData;
string[] roles = userData.Split (',') ;
ctx.User = new System.Security.Principal.GenericPrincipal (fi, roles) ;
}
}
}
if(Session["user"]==null)
{
Response.Redirect("login.aspx");
}
else
{}
if(session["存的session名"] != null)
{
//登陆了
}
else
{
//未登陆
}
{
Response.Redirect("login.aspx");
}