无法调用js文件功能

时间:2014-12-30 05:55:37

标签: javascript asp.net-mvc session-timeout

我正在使用一个js文件,它在用户会话即将结束之前给我一个弹出窗口。我以两种方式使用此文件

1)在Web表单应用程序中 - 它工作得很好。以下是它的代码。 我正在关注this链接

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Session Time Out Warning Message</title>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>

    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js"></script>

    <script src="Script/timeout-dialog.js" type="text/javascript"></script>

    <link href="css/timeout-dialog.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" language="javascript">

        function Timer(time) {

            setTimeout(TimeOut, time);
        }

        function TimeOut() {
            alert(window.location.pathname);
            $.timeoutDialog({
                timeout: 0.15,
                countdown: 60,
                keep_alive_url: window.location.pathname,
                logout_redirect_url: '/AutoSessionTimeOut/SessionTime.aspx',
                restart_on_yes: true
            });
        }

    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="lblMsg" runat="server" Text=""></asp:Label>
    </div>
    </form>
</body>
</html>

cs code:

if (!IsPostBack)
        {
            int _displayTimeInMiliSec = (Session.Timeout - 1) * 60000;

            if (Session["ID"] == null)
            {
                Session["ID"] = "New Session";
                lblMsg.Text = Convert.ToString(Session["ID"]);
            }
            else
                lblMsg.Text = "Old Session";

            ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(),
                "message",
                "<script type=\"text/javascript\" language=\"javascript\">Timer('" + _displayTimeInMiliSec + "');</script>",
                false);
        }

2)我在MVC应用程序中使用它。

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - My ASP.NET Application</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js"></script>

    <script src="Scripts/timeout-dialog.js"></script>
    <link href="Content/timeout-dialog.css" rel="stylesheet" />
    <script type="text/javascript">

        function Timer(time) {

            setTimeout(TimeOut, time);
        }

        function TimeOut() {
            //window.location.pathname = '/Home/Index';
            alert(window.location.pathname);
            alert('hi');
            $.timeoutDialog({
                timeout: 0.25,
                countdown: 30,
                keep_alive_url: window.location.pathname,
                logout_redirect_url: '/Home/Index',
                restart_on_yes: true
            });

        }


    </script>



</head>
<body onload="Timer(15000)">

    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                @Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li>@Html.ActionLink("Home", "Index", "Home")</li>
                    <li>@Html.ActionLink("About", "About", "Home")</li>
                    <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
                </ul>
                @Html.Partial("_LoginPartial")
            </div>
        </div>
    </div>
    <div class="container body-content">
        @RenderBody()
        <hr />
        <footer>
            <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
        </footer>
    </div>

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("scripts", required: false)
</body>
</html>

如上所述,当我在此行$.timeoutDialog({之前发出警报时,警报就会出现,但其余的代码都没有执行,我没有收到任何弹出窗口,我在我的网络表单应用程序中。< / p>

我在MVC申请中做错了什么。请帮忙。

1 个答案:

答案 0 :(得分:0)

我认为timeout参数应该是提到here

的整数
相关问题