当没有互联网连接时,将用户从 asp 登录控件重定向到 html 页面

Redirect user to html page from asp login control when no internet connection

我正在使用应用程序缓存来离线保存页面并设置了回退:这样,如果用户访问我网站上不在应用程序缓存中的任何页面,他们将被重定向到 Home.html .唯一不起作用的地方是用户在失去连接之前打开了 Login.aspx 页面。如果他们然后 select 登录按钮,他们将被发送到标准 'There is no internet connection' 页面而不是我的 Home.html 页面。

当用户没有互联网连接时,我能否获取登录按钮将用户转到我的 Home.html 页面?我在登录页面上使用标准 asp 登录控件。我尝试在 web.config 文件的 system.web 中设置以下内容:

 <customErrors defaultRedirect="Home.html" mode="On">
 </customErrors>

但这似乎没有效果。有谁知道我可以这样做的方法吗?

<customErrors mode="On" redirectMode="ResponseRewrite">
<error statusCode="404" redirect="~/Views/Shared/Error.cshtml"/>
<error statusCode="500" redirect="~/Views/Shared/Error.cshtml"/>
</customErrors>

As you saw here, you can invoke the page to be redirected if these two errors occur. I hope that it helped

您不能使用应用程序缓存来支持登录控件的回退行为。登录控件发出 HTTP POST 和 only HTTP GET is supported.

您可以编写自己的使用 GET 的登录页面,但这意味着用户名和密码将显示在 URL 中,这不是一个好主意,even over HTTPS

也许您可以在 iFrame 中发出登录请求,或者使用 AJAX,如果失败则使用 Javascript 导航到后备页面。

顺便说一句,应用程序缓存支持已经 deprecated,所以也许你应该放弃这个解决方案。