Problems with the Server.MapPath() Function in ASP.Net MVC - c#

I have an ASP.Net MVC application on a server which reads a text document that is on the server. But I'm having trouble with the Server.MapPath() function. I use ASP.Net MVC 6.
Here is the Code i am using to locate the Path and read the file:
string[] texts = System.IO.File.ReadAllLines(Server.MapPath("~/App_Data/Sample.txt"));
Server.MapPath() is not recognized by my program. I am using ASP.Net MVC 6.
I get this Error:
The name "Server" does not exist in the current context.

Related

ASP.Net MVC Application with CKEditor to Azure WebApp gives "Could not start CKFinder: Language file is missing or broken"

I have a ASP.Net MVC Application with CKEditor which helps me to create/edit the images with note.
I placed my images in the azure blob storage and trying to edit them using CKEditor. I have added Azure connector in place. The Application is working in IIS and able to access the images from the blob storage and edit them. But after migrating to the Azure Web App its failing to load the language file with the following error:
"Could not start CKFinder: Language file is missing or broken"
Below link states that mime type is missing and needs to be added:
CKFinder used in CKEditor does not work in my ASP
How do I update it in Azure WebApp(PaaS)?
You should add .json MIME type to your IIS configuration. Please read the docs https://ckeditor.com/docs/ckfinder/ckfinder3-net/quickstart.html#quickstart_troubleshooting_json

ASP.NET Core Accessing Folders Outside Inetpub

I have a ASP.NET Core Web app, the issue I'm experiencing when I deployed on the test server is accessing two folders outside of Inetpub:
C:\Directory\ineedthisone and C:\Directory\ineedthisonetoo. I get Access to path C:\Directory\ineedthisone is denied. I've tried giving permissions to the folder but i still get the same response. Am i missing something?

How to open aspx file inside View Folder for MVC5

Ive got an aspx file, containing report viewer and im trying to open the file using controller. If i put the file in the root, it works using redirect but if i placed it in the Views folder, it wont open. Appreciate any help and thank you in advanced for your help.
The ~/Views directory has a directory-specific Web.config file that adds a rule that prevents all direct-access to files in that directory tree.
To serve WebForms pages in an MVC project you need to move it to another directory that lacks the Web.config rule (e.g. ~/Content), or disable the rule (not recommended).
Your .aspx file doesn't belong in the ~/Views directory anyway as it is not a View (in the MVC architecture) - it's a "page" :)
Note that your project will not work in ASP.NET Core as support for WebForms has been removed in that version.

ASP.NET MVC and IIS Express - Change executing directory

Currently I am working on an ASP.NET MVC application that should use an existing framework. I am hosting this ASP.NET MVC app in IIS Express. Some classes of this framework assume that files are relative to the current directory. Right now the assemblies are executed in c:\users\MyName\appdata\local\temp\temporary asp.net files\root\3c076611\5261f232\assembly\dl3\d36edef7\e39ad394_8136d101.
Is it possible to change this directory?
var rootLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
now load your file as
var filePath = Path.Combine(rootLocation,"relative path to your assembly");
Edit:
if you cannot change framework, then you can change temp directory using web.config, add <compilation tempDirectory="C:\Project\Temp\">, but this will change only "c:\users\MyName\appdata\local\temp\temporary asp.net files\" part, rest of additional folders will still be there

Asp.net MVC 3 Website Loading Failed from server

I have developed an asp.net MVC 3 website. When I upload the site to a server (bin folder in which there are dll files) and Views (in which there all necessary pages) and other folders except coding and also upload the web.config file.
But when I enter a URL in web browser it give me the error:
Server Error in '/' Application. The system cannot find the file
specified
Kindly inform me how to solve this. Thanks in advance.

Categories

Resources