0

我有用于登录的 Default.aspx 页面。成功登录后,它会显示 ItemValuation.aspx 页面,但在地址栏中显示的链接是 Default.aspx。在我的项目中使用 jquery 后,问题就开始了。如果我删除 jquery 引用和代码,那么登录后显示的链接是正确的,即 ItemValuation.aspx 谁能告诉我如何解决这个问题?在 Default.aspx 上成功登录后,地址栏中显示的链接应该是 ItemValuation.aspx 供您参考,我发布了默认页面 aspx 代码。提前致谢。

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

<!DOCTYPE html  >

<html >
<head runat="server">
<link rel="shortcut icon" href="~/Images/ACME.ico">
    <title>Login</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0;"/> 
    <link href="css/jquery.mobile-1.1.0.min.css" rel="stylesheet" type="text/css" />
    <link href="css/jquery-ui-1.8.18.custom_mini.css" rel="stylesheet" type="text/css" />
    <script src="js/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script src="js/jquery.mobile-1.1.0.min.js" type="text/javascript"></script>

</head>

<body >
 <div data-role="page" id ="loginpage" data-theme="c" >
    <form id="formLogin" runat="server" >

    <div id ="DivHeader" data-role="header"  data-position="fixed" data-theme="c"  >
   <div style="text-align:center;top:4px;">
        <asp:Image ID="Image1" runat="server" 
            ImageUrl="Images/ItmVlun.jpg"   />
   </div>
    </div>
    <div data-role="content" style=" margin-top: 2px;">
    <table style="text-align:right;width:100%">
    <tr>

    <td style="width:80%" >
    <table  style="border-color: #FFCC00;width:100%;left:5%; text-align:left;">

    <tr>
      <td style="width:50%;"><asp:Label ID="lblLogin" runat="server" Text="Login:" 
              Font-Bold="False" Font-Names="Copperplate Gothic Light" Font-Size="Large"></asp:Label>
         </td>
      <td style="width:50%;"><input id="txtUserName" type="text" runat="server" style="width:100%;font-size:large;"   /></td>
      <td><ASP:RequiredFieldValidator ControlToValidate="txtUserName"
           Display="Static" ErrorMessage="*" runat="server"  
           ID="vUserName" /></td>
      </tr>

   <tr>
      <td >
          <asp:Label ID="lblPassword" runat="server" Text="Password:" Font-Bold="False" 
              Font-Names="Copperplate Gothic Light" Font-Size="Large"></asp:Label>
       </td>
      <td  ><input id="txtUserPass" type="password" runat="server" style="width:100%;font-size:large;"   /></td>
         </tr>
   <tr>
      <td >
          <asp:Label ID="lblRememberMe" runat="server" Text="Remember Me:" 
              Visible="False" Font-Names="Copperplate Gothic Light"></asp:Label>
       </td>
      <td >
          <asp:CheckBox ID="chkPersistCookie" runat="server" autopostback="false" 
              Visible="False" />
       </td>
      <td ></td>
   </tr>

   </table>
   </td>
   <td style="width:20%;"> 
       <asp:Image ImageAlign=Right ID="Image2" runat="server" 
           ImageUrl="~/Images/LogInimg.jpg"  Width="100%" Height=60% />
   </td>
        </tr>
      </table>  

</div>
  <div  data-role="footer"  data-position="fixed" data-theme="c">

  <asp:Button ID="btnLogIn" runat="server" OnClick="LogMe_Click"
      Text="Log in" data-theme="a"  CausesValidation="False" data-role="button"  data-inline="true" style=" float : left;"  />
  <input type="button" ID="CloseButton"  value="Close" onclick ="window.close();" />
  <asp:Label ID="lblMsg" runat="server" ForeColor="#FF0066"  style=" float : Right;" ></asp:Label>
    </div>

    </form>

    </div>

</body>

</html>

//默认.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; 
using System.Web.Security;
//using System.Web.UI.MobileControls;
using System.Runtime.InteropServices;


namespace Item_Valuation
{
    public partial class Default : System.Web.UI.Page
    {

       // internal static extern int lineGetGeneralInfo(IntPtr hLine, byte[] bCache);
        //public static string IMEI;
        Item_Valuation.User usr;
        public static string message="";
        public string AuthorisationMsg;

        protected void Page_Load(object sender, EventArgs e) 
        {
            try
            {

                if (!IsPostBack)
                {
                    if (Request.QueryString["TCPServer"] != null)
                    {
                        AuthorisationMsg = Request.QueryString["TCPServer"].ToString();
                        GlobalData.SetSettings();
                        lblMsg.Text = "Error: TCP Server IP " + GlobalData.TCPServer + " " + AuthorisationMsg;
                    }
                    else if (Request.QueryString["Message"] != null)
                    {
                        lblMsg.Text = Request.QueryString["Message"].ToString();
                    }


                }

                txtUserName.Focus();
            }
            catch (Exception ee)
            {
                lblMsg.Text = ee.Message;
            }

       }



        private bool ValidateUser(string userName, string passWord)
        {
            if ((null == userName) || (0 == userName.Length))
            {
                return false;
            }


            try
            {
                string msg = "";
                Item_Valuation.User Usr = Item_Valuation.User.CheckLogin(userName, passWord, ref msg);

                if (msg.Length > 0)
                {
                    lblMsg.Text = msg;
                    Response.Write("<script>'alert("+lblMsg.Text +"')</script>"); 
                    return false;
                }
                if (Usr != null)
                {

                }
                else
                {
                    lblMsg.Text = "Invalid Login id or Password";
                    Response.Write("<script>'alert(" + lblMsg.Text + "')</script>"); 
                    return false;
                }
            }
            catch (Exception ex)
            {
                // AcmePayRollBusiness.PayRollError.PostError(this.GetType(), ex, "Error while validating User");
                return false;
            }

            return true;

        }

        public void LogMe_Click(object sender, EventArgs e)
        {
            if (ValidateUser(txtUserName.Value, txtUserPass.Value))
            {
                FormsAuthenticationTicket tkt;
                string cookiestr;
                HttpCookie ck;

                tkt = new FormsAuthenticationTicket(1, txtUserName.Value, DateTime.Now,
                  DateTime.Now.AddMinutes(30), chkPersistCookie.Checked, "your custom data");
                cookiestr = FormsAuthentication.Encrypt(tkt);
                ck = new HttpCookie(FormsAuthentication.FormsCookieName, cookiestr);
                if (chkPersistCookie.Checked)
                    ck.Expires = tkt.Expiration;
                ck.Path = FormsAuthentication.FormsCookiePath;
                Response.Cookies.Add(ck);

                string strRedirect=null;
                //strRedirect = Request["ReturnUrl"];

                usr = (Item_Valuation.User)HttpContext.Current.Session["User"];
                int roleLevel = usr.RoleLevel;

                if (roleLevel != 1)
                {
                    if (strRedirect == null)
                        strRedirect = "ItemValuation.aspx";

                }
                else
                {
                    if (strRedirect == null)
                        strRedirect ="PrinterAssignment.aspx";

                }
                Response.Redirect(strRedirect);
                //Server.Transfer(strRedirect);

            }

        }



}

}
4

1 回答 1

2

jQuery Mobile 就是这样做的。默认情况下,它通过 AJAX 更改所有链接和表单提交。

要禁用这个...有趣的...功能,您需要向mobileinit事件添加一个处理程序,并设置ajaxEnabledfalse.

此处有关如何执行此操作的文档:http: //jquerymobile.com/demos/1.1.0/docs/api/globalconfig.html

于 2012-06-06T06:38:23.337 回答