【问题标题】:IsPostBack on page that requires authentification在需要身份验证的页面上回发
【发布时间】:2014-02-25 13:09:04
【问题描述】:

我有一个包含以下代码的 asp.net 代码隐藏文件:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (User.Identity.IsAuthenticated)
            {

后面的代码用于呈现一些控件,并且应该只对经过身份验证的用户可见;我正在使用 asp.net 身份。

我的问题是:我应该让我的代码保持原样还是像这样重写它会更安全:

protected void Page_Load(object sender, EventArgs e)
{
    if (User.Identity.IsAuthenticated)
    {
        if (!IsPostBack)
        {

谢谢。

【问题讨论】:

标签: c# asp.net identity


【解决方案1】:

最好是第二种方式,因为如果用户确实进行了身份验证,那么只需点击下一个代码。

protected void Page_Load(object sender, EventArgs e)
{
    if (User.Identity.IsAuthenticated)
    {
        if (!IsPostBack)
        {

我已经写了这段代码,就像asp.net页面生命周期一样

S ILVER

  • I-初始化

  • L 负载

  • V 验证

  • 电子事件

  • R 渲染

所以代码看起来更好的方法是

protected void Page_Load(object sender, EventArgs e)//Load
    {
        if (User.Identity.IsAuthenticated)//Validation
        {
            if (!IsPostBack)
            {
              //Rendering
              .
              .
              .
              .

【讨论】:

  • 有趣的术语:S ILVER,+1
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-17
  • 1970-01-01
  • 1970-01-01
  • 2011-04-03
  • 1970-01-01
相关资源
最近更新 更多