could not run ASP.net code in localhost - asp.net

I had enabled the IIS features
and follow the tutorials to build my 1st ASP.NET page
but when I run the code, this problem occer
but it suppose to display current time instead of #DateTime.now()
did I missed out something?

You have to rename the file to .cshtml in order to let it be rendered as Web Page with the Razor engine. See Intro to ASP.NET Web Programming Razor Syntax : The Official Microsoft ASP.NET Site.

Related

Display a custom html page when publishing to IIS in MVC

I have an MVC5 application and I want to display an html (or htm) page while publishing the application to IIS server. So, I tried different methods by using app_offline.htm as indicated on ASP.NET Web Deployment using Visual Studio: Deploying a Code Update. But none of them works properly in MVC. Is there a better approach to make this?
Seems like app_offline.html customization not supported yet. See https://github.com/aspnet/Tooling/issues/530.
Also, there is similar question Custom app_offline.htm file during publish.

How to call ASP.Net pages from a DLL?

I am developing a Web Application in Visual Studio 2008 (ASP.Net C#). My application currently has the following pages:
1. MasterPage.Master
2. Default.aspx
3. Login.aspx
4. Logout.aspx
5. ReportPrint.aspx
Now, I have to in-house-distribute this application to my Developers for further development. For that, I dont want to give pages such as Login.aspx, Logout.aspx, ReportPrint.aspx since they are already complete.
Hence, I compiled these forms in a separate Web Application to create a DLL. Now I am trying to refer to this DLL and call pages which are compiled in it, but without any success.
In windows forms, we can easily refer to Forms from a DLL using :
DllName.FormName.show()
How to accomplish this using ASP.Net?
The markup won't be part of the DLL; so as it currently stands you'll need to give the markup pages (.aspx files) to your team along with the compiled DLL (which will contain the code behind, ie aspx.cs).
See Sharing ASCX-controls between different web applications for other solutions.

How to add Web Pages 2 with razor syntax in an empty web application project in Visual Studio 2012?

I want to create simple Web Pages 2 applications.
I want to use the File->New->Project->Empty Web Application and not the File->New-Web Site.
After i create a new empty web application i cant add a .cshtml file..
The only way that i could do it is:
Nuget -> Install Web Pages 2 with razor libraries
Add->New->Razor MVC View
I am NOT putting the .cshtml file in Views directory. Instead i leave it in root and name it Default.cshtml
Is THIS really the way to do it?
Actually, you can do this. I've done it this way.
Open VS 2013
From the main menu: File > New > Project
Under Installed Templates
Select
Templates
Visual C# (or VB)
Web
(do not select VS 2012)
Select ASP.NET Web Application from the list of projects on the right of screen
Next Screen - Select Empty Project, Check Webforms
Run once, get error for no default page
Only files in project
Global.asax
Web.config
Select "Project" in Solution Explorer
(do not select the Solution)
Select Manage NuGet Packages
Microsoft ASP.NET Web Pages
Microsoft ASP.NET Web Pages Data (Important! Includes WebMatrix dlls)
Add Layout and View pages
Notice the code is recognized as an error
If you run, you get a Server Error that ViewBag does not exist
Change ViewBag to Page
Run again. You should be able to develop like standard web pages but with Razor and no viewstate.
That should be it. I've been doing this since VS 2012 and love the results.
I contacted Scott H. at MS about adding this as a project type. Didn't get
far. He didn't see the point in doing a project this way. IMHO, I disagree.
Web Pages 2 applications are Web Sites, not Web Applications, so you should do the following:
File » New Web Site » ASP.NET Web Site (Razor 2)

I'm having trouble understanding exactly what ASP is and how to upload an ASP website

As of the start of this week I've been required to start learning how to develop websites in ASP. I have a moderate level of experience with C# through XNA, so that part of it isn't much trouble for me.
I've been following a Music Store Tutorial which takes me though setting up an "ASP.NET MVC 3" application.
I'm about done with the tutorial and have a functioning site when I run a test locally, but I don't understand what files need to be uploaded. I've worked on front-end updates for ASP websites before but they were completely different to this in terms of what files made up the site and so on.
I don't see a single .aspx page in my project which is what I assumed an ASP site was made of from experience. I'm starting to think that those projects weren't MVC projects but maybe just the "ASP.NET Web Application" style project.
Are ASP.NET and ASP.NET MVC different? From what I vaguely understand, MVC is just a framework that wraps ASP.NET? Also, is ASP something or is that just a synonym for ASP.NET? Finally back to my initial confusion, what files are to be uploaded onto the server when I want to launch an ASP.NET MVC project?
Do I just upload this entire directory and the server will handle it in the same way that the inbuilt testing ASP server does? Or is the site compiled down into a couple of files somehow and I just upload one of these directories (I think I read that somewhere).
ASP is an acronym for Active Server Pages. Pre .NET, ASP was Microsoft's first iteration scripted web pages. All of those pages typically ended with the extension .ASP.
When .NET was released, ASP was overhauled significantly and renamed ASP.NET. The new version of ASP.NET attempted to model web development similar to windows application development, where you used controls and an event handling model. That was Microsoft's primary model for web page development for many years, and it still around and supported, but today it is referred to as ASP.NET Web Forms. ASP.NET Web Forms pages typically have the .ASPX extension you mentioned.
In the mid-2000s or so, Ruby on Rails took off, using an MVC based model for developing web applications. A few years later, Microsoft released an alternate version of ASP.NET, called ASP.NET MVC, which used similar concepts. Many people feel the MVC approach is a more natural method for developing web pages than the web forms model (note epic Q/A threads on this very site a few years ago). In any case, ASP.NET MVC shares parts with ASP.NET Web Forms, but looks and works pretty differently; for one thing, there are no .ASPX pages as MVC, for the most part, uses a different form of routing to determine what to display.
That's a very brief history that glosses over a whole lot of subjects. What you've posted a screenshot of, is an ASP.NET MVC project.
As far as publishing is concerned, the typical route for publishing an ASP.NET website is to open the project in Visual Studio, select Build|Publish, and tell VS where to put it. Depending on what method you use, you may have to do additional configuration in IIS on the box where you published the site.
First off, when you say ASP, you're referring to old (obsolete) tech. ASP.NET is specifically what you're referring to in your question.
ASP.NET is a Microsoft technology which works cooperatively with the IIS server to provide a "Windows Application" type experience with web sites. Your web site logic is compiled in to a .NET DLL "Class Library." When a web request hits IIS with a URL matching your application directory, IIS starts up your application internally and maintains it.
I don't understand what files need to be uploaded
Visual Studio actually has a built in publisher available for your use. See the Build -> Publish menu in VS / Web Developer.
I don't see a single .aspx page in my project which is what I assumed an ASP site was made of from experience.
ASP.NET Web Forms uses the aspx extension for Pages, their frontend rendering component. On the other hand, ASP.NET MVC uses the concept of Views, which are not relient on a specific component. See the next paragraph.
Are ASP.NET and ASP.NET MVC different?
Yes. No. Maybe. ASP.NET contains all the "magic" which allows IIS - the web server - run the web application and serve up web pages. Volumes could (and have) been written on this. ASP.NET also supports much configuration through the means of Http Modules and Providers. These components are declared and configured through the web apps web.config file and are typically automagically created and persisted by IIS and ASP.NET. They collectively make up the glue that makes ASP.NET just work out of the box.
MVC was built on top of the existing foundation classes of ASP.NET. Some features have been loaned, a few have been replaced and more than a handful have been created in order to support the model-view-controller pattern.
For example, MVC gives us support for View Engines - a runtime library which allows us to write our Views (web pages) in a particular format. The ASPX View Engine existed during MVC's launch. Later came Razor, employing the .cshtml extension. Users of the MVC Framework have implemented a wide variety of their own view engines as well. This is possible due to the modular nature of ASP.NET and MVC.
Do I just upload this entire directory and the server will handle it in the same way that the inbuilt testing ASP server does? Or is the site compiled down into a couple of files somehow and I just upload one of these directories (I think I read that somewhere).
I would recommend using the Build -> Publish menu in Visual Studio. You may use web deploy if your host supports it, but FTP and File System methods are available as well.
The bin folder contains the class libraries required to run your web application on the server. The web.config file provides the configuration to do so. However your Views are not compiled in to the assembly. They are published as-is and are rendered lazily by the view engine.
You are probably familiar with ASP.NET WebForms, this is an MVC project. You can find more here:
ASP.NET MVC
In order to upload the site, you need to publish the website from inside Visual Studio to a local file location and then upload everything to the website.
If the target server doesn't have MVC installed, you can right click on the website project in Visual Studio and select "Add Deployable Dependencies".
This will ensure that the server has all the required files to run an MVC project.

Changing from web site to web project: issue with implementing ConfigurationSection

I am using the ASP.NET Web Site Small Business Starter Kit as a starting point for a simple web app. I wanted to convert it to a web project from a web site for few reasons (better interaction with VisualSVN, etc..). I created a new ASP.NET Web Application from scratch... then copied and pasted all the files via explorer, then did project->create web application. There was some initial errors that I fixed, but now I get this on the original 'items' page:
An error occurred creating the configuration section handler for SmallBusinessDataProviders: Type 'FooWeb.ProviderSettingsValidation' does not inherit from 'System.Configuration.IConfigurationSectionHandler'. (C:\Projects\FooWebFacing\FooWeb\FooWeb\web.config line 5)
Does anyone know why it's giving me this error message that I have to implement IConfigurationSectionHandler? It worked without issue in the ASP.NET Web Site project by just inheriting from ConfigurationSection... And that website was build as .NET 3.5. I tried changing my project to even .NET 2.0 but still no luck - but I don't see how that matters anyway. I am using VS 2008 Developer Edition. Thanks very much for any help.
EDIT: Just to be clear: the same exact code works fine as a web project - but not as a web application. This error makes no sense at all either, regardless of what project its from. Does anyone have any clue how this could happen?

Resources