locked
Request does not have a definition am I missing a using directive or assembly reference RRS feed

  • Question

  • User-605499000 posted

    Hi again,

    I am trying to load issues of a magazine and I am using the program aspnet core 3 mvc.  I copied this file from the old aspnet web file that I used for years.

    Below is the file and I have put * next to the problem.

    using System;
    using System.IO;

    namespace Bumples
    {

    public partial class IssuesDefault : BasePage
    {
    private Int32 issue = 0;
    private String section = "";

    protected void Page_Load(object sender, EventArgs e)
    {
    //
    if (String.IsNullOrEmpty(this.Request.QueryString["Issue"])) (* Request.query string error) 
    {
    this.issue = 1;
    //throw new SecurityException("Error loading Issue!");
    }
    else
    {
    try
    {
    this.issue = Int32.Parse(this.Request.QueryString["Issue"]); (*)
    }
    catch
    {
    this.issue = 1;
    }
    }

    if (issue < 1 || issue > 25)
    {
    issue = 1;

    }


    //
    if (String.IsNullOrEmpty(this.Request.QueryString["Section"])) (*)
    this.section = "";
    else
    this.section = this.Request.QueryString["Section"];

    if (this.IssueName() == "Issue003" || this.IssueName() == "Issue004" || this.IssueName() == "Issue005" || this.IssueName() == "Issue006")
    {
    if (this.User.Identity.IsAuthenticated && (
    this.User.IsInRole("Admin") ||
    this.User.IsInRole("Issue003") || this.User.IsInRole("Issue004") || this.User.IsInRole("Issue005") || this.User.IsInRole("Issue006") || this.User.IsInRole("Register")))
    {
    ;
    }
    else
    {
    //String page = System.Web.HttpContext.Current.Request.Url.AbsoluteUri; // this.GetCurrentPageName();  (*)

    this.Response.Redirect("~/Account/Login.aspx");
    //throw new SecurityException("You are not allowed to edit existent articles!");
    }
    }

    /* Execute */
    this.LoadJavaScript();
    /* Execute */

    }

    private void LoadJavaScript()
    {
    String javaScript = "";

    javaScript += LoadFile("~/Issues/JavaScript/Movime.js");
    javaScript += LoadFile("~/Issues/JavaScript/DivClass.js");
    javaScript += LoadFile("~/Issues/JavaScript/MoveObjectsTo.js");
    javaScript += LoadFile("~/Issues/JavaScript/MemoryClass.js");
    javaScript += LoadFile("~/Issues/JavaScript/Magazine.js");
    javaScript += LoadFile("~/Issues/JavaScript/TalkingBalloon.js");
    javaScript += LoadFile("~/Issues/" + this.IssueName() + "/JavaScript.js");

    Page.ClientScript.RegisterStartupScript(this.GetType(), "", javaScript, true);
    }

    public String LoadCss()
    {
    return "<style type=\"text/css\"> " + LoadFile("~/Issues/" + this.IssueName() + "/CssStyles.css") + " </style>";
    }

    private String IssueName()
    {
    return "Issue" + ((this.issue < 100) ? "0" : "") + ((this.issue < 10) ? "0" : "") + this.issue.ToString().Trim() + this.section;
    }

    private String LoadFile(String fileName)
    {
    //Open a file for reading
    fileName = Server.MapPath(fileName);

    //Get a StreamReader class that can be used to read the file
    StreamReader objStreamReader = File.OpenText(fileName);

    //Now, read the entire file into a string
    String fileContent = objStreamReader.ReadToEnd();

    objStreamReader.Close();

    return fileContent;
    }

    }

    public class BasePage
    {
    }

    Thanks Jen

     

    Tuesday, April 21, 2020 4:42 PM

Answers

  • User-719153870 posted

    Hi bumples18,

    I am trying to load issues of a magazine and I am using the program aspnet core 3 mvc.  I copied this file from the old aspnet web file that I used for years.

    The file you provided should be a webform.cs file, where do you put in your asp.net core 3 mvc project?

    This file won't work since mvc and webform are very different.

    As for the web file itself, the partial class inherited from BasePage which is a custom class has nothing in it, this could cause many issues such as the this in your code won't identify Request. While you said you have used it for years, i guess the usement scenario might be more complex than i thought. So if you juat want to make this web page workable like normal webform page, replace public partial class IssuesDefault : BasePage with public partial class IssuesDefault : System.Web.UI.Page, but it still won't work for a core mvc project though.

    Best Regard,

    Yang Shen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 22, 2020 2:00 AM

All replies

  • User-719153870 posted

    Hi bumples18,

    I am trying to load issues of a magazine and I am using the program aspnet core 3 mvc.  I copied this file from the old aspnet web file that I used for years.

    The file you provided should be a webform.cs file, where do you put in your asp.net core 3 mvc project?

    This file won't work since mvc and webform are very different.

    As for the web file itself, the partial class inherited from BasePage which is a custom class has nothing in it, this could cause many issues such as the this in your code won't identify Request. While you said you have used it for years, i guess the usement scenario might be more complex than i thought. So if you juat want to make this web page workable like normal webform page, replace public partial class IssuesDefault : BasePage with public partial class IssuesDefault : System.Web.UI.Page, but it still won't work for a core mvc project though.

    Best Regard,

    Yang Shen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 22, 2020 2:00 AM
  • User-605499000 posted

    Hi again,

    Thank you for getting back to me and telling me that I need to change these files for mvc.  I will delete them and try to figure out what to do.  I had put them in a Magazine file and did not use controller or model etc. In my old file the base page was in a  cs logic file  .

    I need files that will open the magazine using a default that takes you into the JavaScript file for reading..  I changed the default from aspx.cs to just cs so I presume I will have problems there.  Back to studing.

    Thanks again and sure I will have more questions.

    Jen

    Wednesday, April 22, 2020 2:48 PM
  • User-605499000 posted

    Thanks again made great strides this week.

    Jen

    Sunday, April 26, 2020 2:55 PM