Using class (.cs) files in simple web site. - asp.net

Alright I am a bit of a newb when it comes to ASP.net. I am used to PHP.
Anyway, I am working on a website that is connected to my server via ftp. Everything is working fine, except I just added some classes in the App_Code folder. I cannot access those classes when I go to the page on the web.
I was researching a bit and everyone said I needed to publish the website. Well I did that, and it completely broke. I had to restore from a backup and lost a lot. My own fault though.
The classes work if I am using them on a local web site, but not on the web. Any guidance here? I've tried moving the App_Code folder around with no luck.

the web server doesnt directly execute a .cs file like a .php file. a web server has registered handlers associated with a file extension. when a request arrives, the extension of the file is used to find a dll to process the request. the asp.net web pages model is an easy onramp for people coming from php. http://www.asp.net/web-pages

Related

cannot get aspx files to run on server but it does run locally

Ive made a website in Visual Studio using asp.net, my default page is default.aspx.
Im using FileZilla to add the files to the server, and Ive added everything. But when i type in the URL, it says that it cannot find default.aspx, even though its definitely there.
also, I converted the same page to default.html, and uploaded that and it works fine. Does anyone know why I cant see my .aspx file, and how to fix it.
Thanks
Make sure you have uploaded all the files and the .dll files into the server.
Make sure you have given the correct path and the iis is pointed to the virtual directory of your project.
Check the config file remove debug mode.
Check all the .dll are compiled or not.
In my experience the pages did not work because the server did not support aspx files, although I cannot tell you which version of it it was. I bought a Windows server and it worked fine.

Hiding Sourcecode on IIS Server (ASP.net)

I have a question about hiding or encoding the source code on a server which runs IIS.
At the moment the source code is available and visible for all users who are logged into the server where the IIS Server is running.
Is there a way to hide the Code (encode) with Visual Studio or any other software?
I think the aspx (or *.html) web site code can not be encoded but (for example) the *.vb code sites should be able to encode.
You can simply Publish the website
Build Menu => Publish Web Site
So the code behind files (*.aspx.cs) will get converted to dll(Bin/*.dll) file.
Refer this: Walkthrough: Publishing a Web Site
When you are ready to put your project live make sure that you.
Publish it.
When you publish it that you tell it to compile your code into a single library or code behind files.
If you want to protect your html as well then you should not select to make the site updateable.
These steps will protect your code but as for your web.config file you will need to look at some other articles on securing its info.
If you can, I would recommend ensuring that only the authorized people have access to the server and/or the code base running on the server. If that is the case then you should be ok.
Go to Build menu---> Click on Publish the Website.
then a folder get created on the base folder. and the encoded files are available there. That can be upload to the FTP account, then third party can't see the source code with the browser.

making changes to an asp.net site without reuploading the whole thing

I'm building a site and for the moment, when I want to put it on the web server, I to go Build > Publish WebSite to a local directory and then on the FTP, I delete the whole existing content and then upload the new fresh content that's on my local directory. In the Publish Web Site popup, I see that there's an option for "Allow this precompiled site to be updatable".
If I make changes to some files in my AppCode directory, how do I update the server WITHOUT essentially shutting it down?
Thanks.
Unless you're using a precompiled site or a web application, all "regular" websites are updateable -- App_Code as well as content.
Precompiled sites can be made to be updateable, but I believe only for web pages, not for code files.
If you have a busy site with lots of updates it's possible that updates can break things until they're complete. You can work around that by creating a file called app_offline.htm at the top level of your site. That will effectively take your site offline as long as it's there. The contents of the file are sent to users instead of your active content, such as *.aspx files. When the update is complete, then remove the file.
Try to take a look here: http://msdn.microsoft.com/en-us/sync/bb840038
All that you need is a Synchronization between VS and server.

Asp.net dynamic compilation

With Asp.net web sites and ASMX web services, can some explain what can change once an application has been deployed.
For web sites, I can see that the you can change the aspx files but for web services, I am not sure what can be changed. Any real-world examples of where changing files and dynamic compilation is useful?.
JD.
After deploying the application you can change anything you want to in there. You can change .aspx pages, you can add / remove dlls from the bin folder, you can add / remove code files from the app_code folder, you can add remove stuff from the app_data folder, you can obviously add remove the .asmx files for the web service. I don't see any reason why you cant change anything. go ahead and try changing these things. When you run the code after changes the website will compile again automatically. The things i wrote are written considering that you have deployed the whole code for the website and not a published site !

ASP.NET Routing not firing when site is published to remote host

I have a website that was originally written in webforms to which I have added MVC functionality. When debugging locally it works fine, however, once published and uploaded to my host the routes do not work and return a 404.
I am pretty sure that I have uploaded all the correct files. Would just appear that routing is not working.
Any idea?!
(the site will still serve normal aspx pages fine)
I think the problem may be related to Mixing ASP.NET MVC into ASP.NET WebForms
But I cant see from that thread what the solution was. It looks like it might be something to do with the app_pool mode - but I am running in integrated mode, which is right AFAIK
UPDATE 2
So I think I have routing working. I basically created a new MVC app and went through theweb config file line by line and made sure I have everything I needed. Funnily, none of the tutorials online mention the correct additions you need to make. hey ho..
I have have another issue mind you...
When i load my mvc page I am greeted with the message:
The SessionStateTempDataProvider requires SessionState to be enabled.
I've added a line to web.config to enable sessions (wasn't aware they were off) and it still doesnt work.
UPDATE
I created a new asp.net MVC project and ended up going through web.config line by line and ensuring that everything that related to MVC was included in my hybrid app. Suffice to say that none of the guides mention all the settings that are required (i was using the book professional asp.net mvc 1.0). I then included the global.asax file which is not published and set up a route so that a request for / was not being caught by MVC. I also had to enable sessions in web.config.
And now it works!
Should I mark this question as the answer...not sure on the protocol here :)
I was going through the same thing because I deploy with compiled views. I don't know why but global.asax isn't included in the Release folder that I uploaded. I just figured it was compiled into one of the DLLs. I was getting 404 for everything so I tried uploading global.asax and the site came to life.

Resources