[Experience sharing] of ASP.NET Page_Load performed twice, really (enabled form validation Form Authentication)!

problem found

This is a question from a User's:

 

In truth-seeking and pragmatic attitude, I opened AppBoxPro project, it was found that local commissioning Page_Load entered twice!

In fact, before the test did not, I probably have a direction, because AppBoxPro is required to log in, as does the rights issue is redirected once, but F12 to open the Debug window and found that indeed there is only one request:

 

analyse problem

Prior seems to have encountered a similar problem, the picture looks like a label set up caused by empty src attribute (<img src = "">), checked on the net, there are a lot of people encounter this problem.

For example, this post: https://www.cnblogs.com/Simcoder/archive/2011/12/01/2270256.html

But I checked again on the page, although img tag, but the src attribute is not empty!

 

No way, look at the parameters or debug it, after all, twice to enter the Page_Load total different now, URL requests look at:

 

 

 

 

It was found that the problem, the second request is decoded URL: HTTP: // localhost:? 7086 / ReturnUrl the Default.aspx = / __browserLink ? / RequestData / e176fc91b6574240afa3a4f0f95e9ebd Version = 2 & Version = 2

 

I see __browserLink which seems to have suddenly realized that this is not a tool provided by Visual Studio Well, it seems that only after the introduction of VS2013, allowing users to click the Refresh button to refresh the VS directly corresponding browser window, but I this stuff is not cold, never had been nothing more.

 

Open the page source code, you can see the request came from the:

 

Solve the problem

Know the root of the problem, to solve very simple, there are two methods.

第一种方法简单粗暴,直接禁用VS Browser Link,反正我也没用过:

 

第二种方法是给 VS Browser Link 放行,这个根本不需要进行身份认证,和网站的静态资源做同样的处理,修改Web.config文件:

<location path="icon">
    <system.web>
      <authorization>
        <allow users="*" />
      </authorization>
    </system.web>
  </location>
  <location path="res">
    <system.web>
      <authorization>
        <allow users="*" />
      </authorization>
    </system.web>
  </location>
  <location path="res.axd">
    <system.web>
      <authorization>
        <allow users="*" />
      </authorization>
    </system.web>
  </location>
  <location path="__browserLink">
    <system.web>
      <authorization>
        <allow users="*" />
      </authorization>
    </system.web>
  </location>

 

注意,上面的 __browserLink 配置项就是我们新增的!

 

搞定!

 

 

等等

好像有点问题,既然是一个被拦截的 URL:http://localhost:7086/default.aspx?ReturnUrl=/__browserLink/requestData/e176fc91b6574240afa3a4f0f95e9ebd?version=2&version=2

为啥前面的 F12 看不到这个请求,这个不合理吧!

的确如此,既然是一个HTTP请求,就不可能逃出 F12 的监控,我们再次运行页面,发现这个请求却原来是一个 AJAX 请求:

 

前面我们使用 Doc 过滤项,自然是看不到这个 AJAX 请求了。

 

至此,问题完美解决。

 

 

不忘初心,砥砺前行!

 

Guess you like

Origin www.cnblogs.com/sanshi/p/11279619.html