地址栏显示上一页的地址

时间:2012-06-06 06:07:40

标签: c# jquery asp.net

我有登录的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>

// Default.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);

            }

        }



}

}

1 个答案:

答案 0 :(得分:2)

jQuery Mobile就是这样做的。默认情况下,它会通过AJAX更改所有链接并形成提交。

要禁用此...有趣...功能,您需要为mobileinit事件添加处理程序,并将ajaxEnabled设置为false

这里有关于如何做到这一点的文档:http://jquerymobile.com/demos/1.1.0/docs/api/globalconfig.html