【发布时间】:2015-02-18 11:05:15
【问题描述】:
我的模态弹出会话超时扩展器行为不端。
我正在尝试实施上一个问题 (Maintaining page number in DropDownList after postback to refresh server timeout) 中给出的解决方案。
我遇到一个错误:尝试使用 POST 请求调用方法 \u0027Check\u0027,这是不允许的。"," 我一直在研究该错误,简单的解决方案似乎是该请求不是发布请求。我试过删除 runat="server",添加 "return:false;"到 onClick,并在脚本中添加“return false”。
有没有办法让它工作?
我的 .asmx 网络文件:
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class SessionKeepAlive
Inherits System.Web.Services.WebService
<WebMethod(EnableSession:=True)> _
<Script.Services.ScriptMethod(UseHttpGet:=True)> _
Public Function Check() As String
If HttpContext.Current.Session("username") Is Nothing Then
Return "expired"
Else
Return "ok"
End If
End Function
End Class
我的弹出html:
<asp:Panel ID="pnlSessionTimeout" runat="server" CssClass="modalPopup" Style="display: none;"
Width="300">
<table style="width: 100%;">
<tr>
<td style="color: #FFFFFF; font-weight: bold; background-color: #51516A" align="center">
WARNING! Session About to Expire
</td>
</tr>
<tr>
<td>
<p>
Your session will time out in
<asp:Label ID="lblTimeoutCount" runat="server" Text=""></asp:Label>
minutes. Click the ‘Continue’ button to keep working.
When the timer reaches 0:00 your online session is no longer active.
<asp:UpdatePanel ID="updpnlCountDown" runat="server">
<ContentTemplate>
<span id="CountDownHolder"></span>
</ContentTemplate>
</asp:UpdatePanel>
<br />
<br />
<span style="text-align: center; display: block;">
<asp:Button ID="btnPreserveSession" runat="server" CausesValidation="false" Text="Continue"/>
</span>
<br />
</p>
</td>
</tr>
</table>
</asp:Panel>
<cc1:ModalPopupExtender ID="mpeSessionTimeout" runat="server" TargetControlID="pnlSessionTimeout"
BackgroundCssClass="modalBackground" BehaviorID="mdlSessionTimeout" DropShadow="false"
OkControlID="btnPreserveSession" OnOkScript="PreserveSession()" PopupControlID="pnlSessionTimeout">
</cc1:ModalPopupExtender>
我的 ajax 脚本调用:
function PreserveSession() {
{
$.ajax({
type: "POST",
url: "SessionKeepAlive.asmx/Check",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: checkAuthenticatedOk,
error: checkAuthenticatedError
});
}
【问题讨论】:
标签: javascript asp.net vb.net asp.net-ajax