ASP.NET Webmatrix using .aspx instead of Razor - asp.net

I would like to know if there is a tutorial that teaches how to build your pages in Webmatrix but using .aspx and not razor.
All the tutorials I've found so far only teaches Razor syntax and I can't use that because my webhosting doesn't support .cshtml.
I would like to connect to a database and performs SQL Querys, so a tutorial or article that shows how to do that will work for me.
Thanks.

Not possible. ASP.NET Web Pages (what you're using in WebMatrix) ONLY uses Razor.
I seriously doubt your host doesn't support CSHTML files. If they support .NET 4.0, then they support CSHTML files. Nothing else needs to be installed on their servers.

Your hosting provider doesn't have to support .cshtml pages. Unlike Web Forms, which use a .aspx extension on the URL, and must be mapped in the IIS configuration, Web Pages uses Routing and by default drops the suffix, so no configuration is needed by the hosting provider.
When you publish a Web pages site, it copies the necessary razor rendering files to the bin directory.
It's not possible to have a Web Pages site without Razor.

Related

Is it possible to host an asp.net MVC in the same folder as asp.net web forms app?

I have a domain and a hosting account and I'd like to in a folder host an MVC app and in another host asp.net web forms app.
Is it possible?
Yes, ASP.NET web forms and ASP.NET MVC applications can reside side-by-side in the same application. I have that in my current application and it works fine. You just have to make sure that your classic ASP.NET application paths don't conflict with your ASP.NET MVC routes -- seems that the MVC routing handler wins out. I've run into that a few times.
Here's a good article that walks through hosting web forms and MVC side-by-side.
As others have said, this is most certainly possible. You'll likely want to modify your MVC routes to ignore requests for aspx or axd resources:
routes.IgnoreRoute("{resource}.aspx");
routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
Yes, it is possible. You can also have different web.config files for each folder. Of course, it depends on the hosting .NET version, if you can use MVC..
You can also have your single hosting host multiple domains, or make a subdomain and host the legacy site there.
This article shows in details how to do this: http://www.hanselman.com/blog/IntegratingASPNETMVC3IntoExistingUpgradedASPNET4WebFormsApplications.aspx

How does ASP.NET WebPages implement extensionless URLs?

I'd like to implement the same thing for my own build providers.
I'm talking about an ASP.NET Webpages application, in Visual Studio: File > New Website > ASP.NET Website (Razor)
Works with Cassini, so it's not an IIS Express thing.
I found it, it's an HTTP module, System.Web.WebPages.WebPageHttpModule
This module checks if the file exists, and if it does it creates a handler from that file and remaps the request to that handler.
Razor is a templating engine. It has nothing to do with URLs. They are handled by the ASP.NET routing engine. Extensionless URLs are supported starting from IIS 7.0. In IIS 6.0 you need to associate the aspnet_isapi extension with all incoming requests if you want to support extensionless urls.
I found this information in regard to the "Routing" that you might find handy if you are building an ASP.Net WebPages site w/o MVC3 and wanted to mention it.
Creating More Readable and Searchable URLs - About Routing
HTH

Having URL without .aspx extension

I noticed a lot of ASP .Net sites does not have the URL ending with ".aspx".
An example would be:
- https://stackoverflow.com/questions
Did they create a Questions folder and put a Default.aspx inside?
In that case, wouldn't there be A LOT of default.aspx in many folders which is hard to maintain (even though it is user-friendly)?
Thanks y'all.
StackOverflow is written using ASP.NET MVC. The MVC framework does not use .aspx files.
The way it works internally is by using routing tables - see an overview here.
You can also do this with ASP.NET and .aspx files or you can use URL rewriting. You can read about the differences here.
You can refer to any URL rewriter or a routing technique for that. If you look at the new AS{.NET MVC, it works on that model only.
You can use Url Rewriter to remove extensions from the urls of your website.
ASP.net has a routing framework you can use even if you are not using ASP.net MVC
Official documentation: http://msdn.microsoft.com/en-us/library/cc668201.aspx
Also as previously stated ASP.net MVC works like this out of the box and you can also use URL Rewriting
With ASP.NET 4.0, you get the benefits of URL routing (nice, clean URLs) with ASP.NET webforms, too — see:
Routing for Web Forms in ASP.NET 4.0
URL Routing with ASP.NET 4 Web Forms (VS 2010 and .NET 4.0 Series)
Basically, what you do is define a route like
/question/{id} or /question/{title}
and you then define what ASPX page this is being routed to. Quite nifty!

ASP.NET ascx.cs via GET

Say I have this url:
http://site.example/dir/
In this folder I have these files: test.ascx.cs and test.ascx
Just to be clear, I am not a .NET developer.
From a security point of view - why can't I access http://site.example/dir/test.ascx.cs and how secure is it to keep those files there?
I assume IIS filters out request that query these kind of files, but can someone explain me this?
Thank you.
You just explained it yourself. IIS won't serve those files.
When you register ASP.NET with IIS (aspnet_regiis.exe) it will add common extensions and associate them with the ASP.NET handler. As far as the .cs extension is concerned it is filtered and not served by IIS. It is absolutely safe to have these files there, but I would recommend you to use an ASP.NET application project (in contrast to ASP.NET website) which is precompiled and you don't need to deploy source code files on your server.
(source: wewill.cn)

How to add custom ASP.NET pages into sharepoint

How to add custom ASP.NET pages into sharepoint?
I am very new to sharepoint but what I realized is that I can only make plain text pages or links. but what if I have a website already built in ASP.NET and want to add it through sharepoint.
Or is it possible to build the website itself from sharepoint including dynamic server side controls like buttons, trees ....
Simple answer: put your *.aspx files in inside the _layouts folder, usually located at
c:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\
afterwards you can access you page (named page1.aspx for example) through the sharepoint site by:
http://your site name/_layouts/page1.aspx
You can have inline code and/or code-behind, just like in a normal aspx page.
However, please note that pages added through this method are called application pages, meaning that they cannot be customized (easily) by the user and are available under all site collections in your farm.
SharePoint supports another kind of pages, called Site Pages which are site-specific, you can read more about them here.
See these questions which should cover everything you need:
How would you convert an ASP.NET site to work as a SharePoint site?
Moving from custom ASP.NET application to Sharepoint Services
Deploying custom Asp.net applications to same IIS site as Sharepoint
SharePoint - ASP.Net Controls Integration
Sharepoint controls in ASP.NET application
Also this page on SharePoint Dev Wiki.
This Visual How To walks you through the process of creating an application page step by step.
Creating an Application Page in Windows SharePoint Services 3.0
http://msdn.microsoft.com/en-ca/library/bb418732.aspx
The presenter of the video, Ted Pattison, has a book that is a great resource to help you get up and started with SharePoint development.
Inside Windows SharePoint Services 3.0
http://www.amazon.com/dp/0735623201?tag=g6consulswebs-20
If you want some .aspx-Pages in a SharePoint-Website, you can build a SharePoint-Module Feature containing the .aspx-Pages.
See How to: Provision a File and Create and Use a SharePoint Feature Package

Resources