Publishing asp.net single page to ftp server? - c#

i'm trying to publish a webpage into my ftp server, thing is when i publish it and try to access it, the result is just pure code . How can i make it so that only the "design" of the asp file appears?
Thanks in advance,
Bruno Charters

How can i make it so that only the "design" of the asp file appears?
If all you want to appear in the browser is the "design" (meaning no server-side logic). Then all you'd really need is an HTML page. To do so:
copy the markup rendered by the .aspx file from the browsers source
paste the markup into an appropriately named .html/.htm file
upload the file to your server
If there is server-side logic then you'll need to upload the .aspx file to a server that has IIS and the appropriate version of the .NET Framework to run the page.

You will need to compile your code before you publish it. Compiling your code basically moves all the logic into the .dll file and leave only the HTML (well, at least). You will still need a Web Server with aspx processor, typically IIS.
You will need to point your Web Server to the folder you are uploading to.

Related

How to insert a html file that references other scripts in cshtml file?

I have a html file on a network drive (the same network my where my server runs) and I want to show it to the users. So I tried to do the following:
#Html.Raw(File.ReadAllText("//path/on/netwotk/drive.html")
The problem is that html file references other files in the same folder (mostly js scripts)
And the server tries to look for them in his url (localhost/relative/path/to/file) instead of in the network drive.
How can I tell the server to look for the files in the same folder?
What you are trying to do is extremely bad practice. You shouldn't be doing it this way.
How this works
When you call the following method:
#Html.Raw(File.ReadAllText("//path/on/netwotk/drive.html")
the HTML helper runs on your server side. It loads all the content from the file you have specified and sends it to the browser exactly the way it's written in the file. And it only reads that specific file and nothing but that file.
The client-side markup in your browser doesn't know anything about the folder on your network drive. It just can't possibly know it. The browser can be on anyone's device.
When your browser sees relative paths in the HTML markup, it will try to send a GET HTTP request to obtain those. And the address it will be using will have the same base URL that it got its original page from followed by the relative path, as specified in the HTML. And it cannot find it, because there is no such thing. That file doesn't exist at that address.
The paths that you see in HTML are not relative to the folder structure. They are relative to the address that the browser can access. It's just that if you place the static resources into actual folder on your host, those paths will map to the paths after the base URL in the browser.
What you should do instead
There is no scenario in real life where you would want to access HTML, JavaScript and CSS via some remote folder. Just place them into the folder on the actual host machine. They should be part of your actual application. It is totally acceptable to have multiple copies of those for multiple environments.
In the context of ASP.NET application, those resources are known as static files. And you can enable those, as if you are running an old-school website. This is where you can find the documentation on how to work with them:
Static files in ASP.NET Core
Your other alternative is to rewrite the code from those HTML files and put it into your Razor views.

ASP.net page not loading CSS with error Failed to Load Resource

I have asp.net application which I am running on local host. When I browse page loads but its not able to pick any css and js and I get error as
Failed to load resource: the server responded with a status of 404 (Not Found)
(see screenshot) .
Any pointer as to what could be wrong here?
On a different server, same page loads fine with all images.
Check your paths -- you may need to use a relative path instead of an absolute. Also, confirm that you can navigate to the css and js files from your browser using the path that you see in the console (you probably will not). Finally, check your IIS settings and make sure you can server Static files.
Include all your files or css and any from Project PC to Deployment server

Uploading files to IIS server

I just wanted to ask is it possible to upload files to IIS server? If it's possible please describe me how to do it, thanks. I've been using google since 1h and i found nothing.
If all you need is file upload to your web server, you could set up FTP on your server
http://www.iis.net/learn/install/installing-publishing-technologies/installing-and-configuring-ftp-7-on-iis-7
If you are looking for a file upload capability for your web application, you can use the FileUpload control. The file would be POSTed to your page once you submit your form. The MSDN page has a an example of how to use the control and save the file on the server side.
Create a web application that has file upload capability
Host the web application in IIS.
Files uploaded will be dropped in your applications folder.
Take a look at for an example of file upload with WebApi: http://blogs.msdn.com/b/henrikn/archive/2012/03/01/file-upload-and-asp-net-web-api.aspx

jquery not working in asp.net mvc after publishing to localhost

I've built an mvc application which contains some jquery code. When I run the app from my ide, everything works perfectly. When I publish to the server and open the page, the jquery does not work. I get object expected errors.
i am not getting anything in the page,it shows error in loading dhtmlxsheduler.js
can you help me out
You issue is most likely due to the way you are defining the path to the JavaScript file you are loading.
Make sure that you use a relative path, and not an absolute path when calling the file source.
If you have runat="server" you can also use the ~ operator, which ASP.Net translates to your home directory.
Read more here http://msdn.microsoft.com/en-us/library/ms178116.aspx
Your links to the .js files are broken. See the source code of your pages in your browser, and check the tag's src attribute. It must be pointing to the wrong place.
My guess is removing ../ do you have iis express? or development server? or iis?
Or use a CDN like this one from Google:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

Load asp.net website inside winform C#

I have a(n) (MDI) Windows Form application. It contains two forms. One form (Measured data) controls an engine, another form (laboratory) should show my asp.net web site that has various assignments for the user to do.
How can I show the asp.net default page in that laboratory form? I'm using awesomium to make a browsing window in my laboratory form.
Doing the following
webView.LoadURL("file:///D:/school/4e%20jaar/Erasmus/ErasmusProject/Laboratory/deault.aspx");
gives an error. Probably because the asp.net site isn't online. but how can I run the site so I can see the default.aspx page?
I have on solution with three projects
ErasmusProject
ASP.NET website
SIMOclasses
SIMOForm
The problem is you cannot execute aspx files with file:/// path.
You have to execute on IIS.
So first thing you have to do setup iis if you didnt, create new web site (or use Default Web Site) to execute your aspx files, than change your link file:/// to http://localhost or something.
The URL you've specified looks like its accessing the raw file via the file system. i.e. file:///D:/.../default.aspx.
(You've also misspelt 'default' in your question!)
Can you access that URL from a browser (e.g. IE, Firefox, etc) and see the content you want? I suspect you can't and that you're missing the webserver that is compiling and serving the .aspx pages.
You should host your website first :
WebDev.WebServer /port:9999 /path:"C:\Projects\MyWebSite"

Categories