SQL Server script on web server - c#

I am a newbie to asp.net. I recently publish an asps site from Visual Studio using C#, but I realised that the scripts I wrote for the buttons, links, etc to interact with my database on local machine is missing when I publish the pages.
Do I have to rewrite the code for the pages now on the web host?
Your advice is needed.
Thanks

It's really hard to answer such a question, no details, no code, and things disappearing mysteriously. However, given that you're newbie and from the description that you have, I will try to give you some tips that will hopefully set you in the right direction.
Firstly, I don't know exactly what you mean by "script", so I will assume you're referring to what is called code-behind. ASP.Net is different from many other web application frameworks in that it is compiled. So you have the front-end of your aspx pages which has a mixture of HTML and ASP server-side controls, and then linked to each aspx page you have an aspx.cs code file for the code-behind.
Now, when you're ready to upload your project to the hosting, you should use the Build => Publish menu. This will compile your project in Release mode. All the aspx.cs pages will be compiled into a dll, so you will not see them among the file that are uploaded to the hosting, and you cannot modify them. The aspx pages are typically not compiled (although you can configure that), so you will see them and you can still modify them.
As for the database connection, when you're writing your code, you typically connect a local database on your computer. You should have the connection string in the web.config file in the root folder of your project. However, the connection string for the hosted database is likely to be different, so make sure you have the correct connection string for the hosted database in the web.config before you upload your code to the hosting.

I think this will answer your question. It's a setting on a file level, available on properties (F5) for the file:
Visual Studio 2010 Web Publish missing a file
Once you set it and republish, the file will show up in the publish location.

Related

How do I modify and deploy Edit.aspx in Kentico 7?

We are on kentico 7 and for some reason, none of my edits to Edit.aspx are showing up locally or on our dev server. Usually, I just modify a .aspx or .cs file on my local machine and they appear on my local server when I launch the site. Is there a special way to modify/deploy this file? The file full path is: site\CMSModules\Content\CMSDesk\Edit\Edit.aspx.
Best practice is to NOT modify any of the Kentico base files. BUT I'm assuming here since you're on v7.x that you're most likely not upgrading to a new version any time soon so this will come down to how your site is set up. Is it a website or a web project? Website will have an /App_Code directory.
If you have an /App_Code directory, then you'll make the changes to your ascx and .cs files and copy them to your production server. If you have a web project, then you'll need to build the project and redeploy the site, including the new dll, to your production server.
Don't ask how to copy the code to your servers because that will be something you need to figure out on your own on how to access your production servers. Don't reply with any of your dev or prod server info, it's not a good idea at all.

What is contained in a published ASP.net project?

I developed a site in asp.net using C# as the language.
I have debugged it and no more errors can be found and can also view the page from a browser.
I would like to host this site and direct a client to it for demo purposes but am having a problem each time I publish my site. The publishing only does away with all my .aspx.cs files but I don't see any .exe file that I can install or send to my hosting provider.
I would like to know if this what I am experiencing is normal or there are settings I need to do in my visual studio 2013 ultimate edition for these tasks to be performed?
Kindly advise me on the way forward
ASP.NET applications (not "ASP.NET websites") are compiled into a .dll file in your bin folder, which is then deployed on to the server.
Your .aspx/.cshtml1 files reference compiled classes and types contained within this DLL, thus eliminating the need for source files.
There won't be any .exe files, you need to deploy your project to a web server, like IIS. Check out this link.

Visual studio web, what file do i upload to server?

I'm a little confused, since a day or 2 i've been programming with visual studio 2013 web express. i've made a C# web form (.aspx). i used to program normal html/css in Adobe Dreamweaver.
But unlike a normal .HTML document i cannot find a file to just click and open in my browser. and so i do not know how to upload my project to my hosting server. when i debug it, it shows up in my browser and it tells me it is the file with .aspx extension but when i try to manually open this file it just tells me there's something wrong with my page (incorrect code etc.)
Anyone can tell me how i do this? could not find a solution in google so i thought i'd give stackoverflow a chance :)
Thanks!
Gr.
First off, a website programmed with ASP.Net requires Internet Information Services (IIS) to run.
Visual Studio has its own built-in mini version of IIS for development, but to deploy to production you'll need a Windows Server with IIS. You should check that your hosting provider supports IIS before you do anything else.
Assuming you have IIS running, and you've configured a website in IIS with an empty directory, ready to host your project there are a couple of different options you have for deployment:
Just copy everything in the website to the server (all files & folders). This is simplest, and allows you to tweak things on the fly, but is the least secure.
Use Visual Studio's packaging and deployment utility. Not much to say here, other than read the manual.
The .aspx pages, .ascx controls, the bin folder with your .dll files, web.config, App_Themes, App_LocalResources, etc. And then you'll need to set up a new web site on IIS.

How to prepare an asp.net app for xcopy deployment?`

I have an asp.net application that I currently deploy to 4 different environments on the client's servers. At the moment we deploy by copying over individual assemblies and content files but the whole process is time consuming and error prone. Basically I'd like a method of preparing the application for deployment that will give me a folder containing the application (no source code etc). No IIS changes are required. It would be good if I could specify different webconfigs for different environments.
I've looked at msbuild, msdeploy, etc and I'm not even sure which is the right tool for the job. I'm tempted to go with a batch file that copies only certain file extensions but I'm sure there must be a better way of doing this. Any help please?
Take a look at the Visual Studio Publish Web Site feature.

Does publishing an ASP.NET website give any extra security benefits?

I come from a PHP/Rails background where deploying a website often means FTP/Checkout of the source code in the correct directory on the web server.
However, I've been asked to develop an ASP.NET website and some people have advised me to "Publish" the site instead of copying over the source code directly. Apparently, this converts the codebehind (.cs) files into compiled DLL's etc.
My application does not contain any specific secretive business logic. It's a common shopping cart app. My question is if this is a good idea? How does not making the C# code reside on the server make the app more secure?
ASP.NET code will always be compiled - either:
At run-time - you can copy .ASPX and
.CS files to the server. When a page
is requested the .ASPX and .CS files
will be compiled on-the-fly. The
ASP.NET run-time will create a DLL
containing the compiled code (this
lives in a folder called Temporary
ASP.NET files and the location
depends on the version of .NET
you're using).
Pre-compiled - you can choose to compile your code before deploying it to your server. This is what the Publish command does in Visual Studio. It compiles your .ASPX and .CS files into (one or more) DLLs that are then uploaded to the web server.
Personally, I don't think there's much of a security benefit from deploying pre-compiled code (unless you're obfuscating your pre-compiled DLLs).
That said I prefer it for these benefits:
It seems tidier, at least to me, than having a bunch of .CS files littered in a folder
There's a small performance benefit of not having to do C# compilation. Note your code will still need to be JITed from IL to native code and this still incurs the initial request performance hit (unless you use new ASP.NET 4.0 and IIS 7.5 features or something else).
The Publish feature lets you package your application up for deployment to other environments (testing, pre-production, production, etc.)
Note: coming from Rails/PHP you might like to keep on deploying both .ASPX and .CS files to your server. The benefit is that it's easier to modify a running application in a way you may be used to doing. This isn't a great practice if you're following a rigorous deployment lifecycle but it can be useful in some cases.
I can make one addition to the precompiling though, which has been mostly about security and performance; compiler checks!! Without precompiling you can easily upload some code file containing errors but not find out before 13 days later when the first user hits the page using this code-file. This is due to the fact that asp.net will only compile one file at a time whenever its needed.
With precompiling ALL the files will be compiled and ALL compiler errors be caught right away.
Thats all about precompiling though but publishing is not just about that.
Another important factor is the steps you can instruct msbuild to execute during publish. Maybe the most important thing is web.config transformation which you can read about here http://msdn.microsoft.com/en-us/library/dd465318.aspx. Basically you can create a transformation file that during publishing will replace/add/remove values from your web.config based on the publishing target.
Your c# code is still residing on the server, it's just residing as a compiled code instead in the form of a script as you are used to in PHP/Rails.
In PHP, rails or classic ASP, you write scripts and xcopy / ftp to your webserver. PHP interpreter then parses the script everytime a web request comes in vs. in asp.net the code is compiled and then copied to the webserver, so when a web request comes in, the execution is much faster.
Think of it broadly as deploying an .exe file on the server vs. writing the program in a text file and making a compiler parse the text file and running it every time.
It has nothing to do with being more secure or not.
Btw - How's life after Bluebells School :-)
Yes, it's more about compiling than anything else. For the website to be able to run, the C# code must be compiled and that is what the publish step does, together with transferring it to a specific location.
The version of the website you have on your desktop is a development version, most likely with debug versions of the compiled code. With the publish step however, you should generate a release versions of the compiled code which also improves performance.
The publish step of ASP.net can be compared to creating an installer of a normal Windows application and, when published to an operational server, the install step combined.

Categories

Resources