Answered by:
changing asp.net files to asp.net core mvc files

Question
-
User-605499000 posted
Hi,
I have a magazine on the web that was using asp.net web files. I am changing to asp.net core mvc files. The magazine is JavaScript files. I changed the default aspx files to html and cs files in the www root files. Is there a way that I can have a folder on the main part of core files with the htm, cs and javascirpt files instead of in the www.root folder.
Below is the new html file and cs that that should open the JavaScript mag.
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head><head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimal-ui">
<meta name="apple-mobile-web-app-capable" content="yes" />
<title>Bumples Magazine</title>
<link rel="shortcut icon" href="../Bumples/FavIcon.ico" />
<link rel="icon" type="image/x-icon" href="../FavIcon.ico" /><link rel="stylesheet" type="text/css" href="../Css/MagazineStyles.css">
<script type="javascript/text"></script>
<script src="jquery.js"></script>
</head><body onLoad="BmOnLoad();">
<form id="form1" runat="server">
</form>
</body>
</html>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"]))
{
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("Administrators") ||
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;
}}
}
Thanks,
Jen
Wednesday, April 1, 2020 10:18 PM
Answers
-
User-605499000 posted
Hi Sherry,
Thanks again for helping me. I had put a static folder in the startup but it wasn't working. The one you sent me should work. I have moved the issue file out of the www root. I need to make major changes to the default and started working on that today. I am sure that I will have other questions for you.
Thanks again for everything,
Jen
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, April 2, 2020 11:36 PM
All replies
-
User-854763662 posted
Hi bumples18,
Is there a way that I can have a folder on the main part of core files with the htm, cs and javascirpt files instead of in the www.root folder.Did you want to serve files outside of web root ? From the official documentation, you could configure the Static File Middleware as follows:
public void Configure(IApplicationBuilder app) { app.UseStaticFiles(); // For the wwwroot folder app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider( Path.Combine(Directory.GetCurrentDirectory(), "MyStaticFiles")), RequestPath = "/StaticFiles" }); }
Best Regards,
Sherry
Thursday, April 2, 2020 3:06 AM -
User-605499000 posted
Hi Sherry,
Thanks again for helping me. I had put a static folder in the startup but it wasn't working. The one you sent me should work. I have moved the issue file out of the www root. I need to make major changes to the default and started working on that today. I am sure that I will have other questions for you.
Thanks again for everything,
Jen
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, April 2, 2020 11:36 PM