Solved

ASP/JS Classic page, create session error

Posted on 2014-02-19
9
703 Views
Last Modified: 2014-02-19
I have the following code that is used to filter out a recordset based on values from a form.
I need to add code to create a session value based on the returned value from one of the fields.

--- code----

<%
// *** Validate request to log in to this site.
var MM_LoginAction = Request.ServerVariables("URL");
if (Request.QueryString!="") MM_LoginAction += "?" + Server.HTMLEncode(Request.QueryString);
var MM_valUsername=String(Request.Form("username"));
if (MM_valUsername != "undefined") {
  var MM_fldUserAuthorization="";
  var MM_redirectLoginSuccess="forgotpasswordsent.asp";
  var MM_redirectLoginFailed="forgotpasswordnotfound.asp";
  var MM_flag="ADODB.Recordset";
  var MM_rsUser = Server.CreateObject(MM_flag);
  MM_rsUser.ActiveConnection = MM_CMS2003_STRING;
  MM_rsUser.Source = "SELECT Loginid, Email";
  if (MM_fldUserAuthorization != "") MM_rsUser.Source += "," + MM_fldUserAuthorization;
  MM_rsUser.Source += " FROM dbo.vuEmailreset WHERE Loginid='" + MM_valUsername.replace(/'/g, "''") + "' AND Email='" + String(Request.Form("Email")).replace(/'/g, "''") + "'";
  MM_rsUser.CursorType = 0;
  MM_rsUser.CursorLocation = 2;
  MM_rsUser.LockType = 3;
  MM_rsUser.Open();
  if (!MM_rsUser.EOF || !MM_rsUser.BOF) {
    // username and password match - this is a valid user
    Session("MM_Username") = MM_valUsername;

    if (MM_fldUserAuthorization != "") {
      Session("MM_UserAuthorization") = String(MM_rsUser.Fields.Item(MM_fldUserAuthorization).Value);
    } else {
      Session("MM_UserAuthorization") = "";
    }
    if (String(Request.QueryString("accessdenied")) != "undefined" && false) {
      MM_redirectLoginSuccess = Request.QueryString("accessdenied");
    }
    MM_rsUser.Close();

    Response.Redirect(MM_redirectLoginSuccess);
  }
  MM_rsUser.Close();
  Response.Redirect(MM_redirectLoginFailed);
}
%>

----

The session variable I need to add is:

Session ("userloginid")=(EmployeeLogin.Fields.Item("userloginId").Value)

---

I am just not sure where to add that code.
0
Comment
Question by:amucinobluedot
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 33

Assisted Solution

by:Big Monty
Big Monty earned 400 total points
ID: 39871792
I would put it right after your first IF statement after you validate the user:

 if (!MM_rsUser.EOF || !MM_rsUser.BOF) {
    // username and password match - this is a valid user
    Session("MM_Username") = MM_valUsername;

    Session ("userloginid")=Request.Form("userloginId")
0
 
LVL 33

Assisted Solution

by:Big Monty
Big Monty earned 400 total points
ID: 39871798
this assumes there is a field on the previous page that is named userloginId
0
 

Author Comment

by:amucinobluedot
ID: 39871827
Yes, but the value does not come from a form but the recordset

I tried adding this below, like this:

  if (!MM_rsUser.EOF || !MM_rsUser.BOF) {
    // username and password match - this is a valid user
    Session("MM_Username") = MM_valUsername;
      Session ("reqloginid")=Request.Form("userloginId")

On the next page I try to retrieve the session value, but doesn't display anything. Even tho the check was successful and a record was found.

I have:  Session: <%=Session("reqloginid")%>

Displays nothing.

If I try to add your code I get:   An intrinsic object cannot be stored within the Session object.

    // username and password match - this is a valid user
    Session("MM_Username") = MM_valUsername;
      Session ("reqloginid")=Request.Form("username")
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

Author Comment

by:amucinobluedot
ID: 39871834
If I do this:

  MM_rsUser.Open();
  if (!MM_rsUser.EOF || !MM_rsUser.BOF) {
    // username and password match - this is a valid user
    Session("MM_Username") = MM_valUsername;
      Session ("reqloginid")=(EmployeeLogin.Fields.Item("UserLoginId").Value)

    if (MM_fldUserAuthorization != "") {
      Session("MM_UserAuthorization") = String(MM_rsUser.Fields.Item(MM_fldUserAuthorization).Value);
    } else {
      Session("MM_UserAuthorization") = "";
    }


I get this error:

Microsoft JScript runtime error '800a138f'

'EmployeeLogin.Fields' is null or not an object

/bluedot/forgotpassword.asp, line 29
0
 
LVL 33

Assisted Solution

by:Big Monty
Big Monty earned 400 total points
ID: 39871835
your original post said to retrieve the login ID from a field. If you want to do it from the recordset, you would do:

 if (!MM_rsUser.EOF || !MM_rsUser.BOF) {
    // username and password match - this is a valid user
    Session("MM_Username") = MM_valUsername

    Session ("userloginid") = MM_rsUser("loginID")
0
 

Author Comment

by:amucinobluedot
ID: 39871836
Without this line:

Session ("reqloginid")=(EmployeeLogin.Fields.Item("UserLoginId").Value)

It succeeds and moves to the next page but I get no ID from the record that was filtered, which is what I need.
0
 
LVL 33

Accepted Solution

by:
Big Monty earned 400 total points
ID: 39871841
EmployeeLogin is not your recordset object, MM_rsUser is. You want to reference MM_rsUser
0
 
LVL 10

Assisted Solution

by:Banthor
Banthor earned 100 total points
ID: 39871904
right under
Session("MM_Username") = MM_valUsername;
0
 

Author Closing Comment

by:amucinobluedot
ID: 39872036
Thanks all !
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question