Friendly URLs with WebMatrix and razor - asp.net

I'm new to ASP.NET and I'm learning first in WebMatrix using razor syntax.
In PHP I used .htaccess to route URLs to database posts, for example:
http://mywebsite.com/linux/how-to-install-wamp-in-ubuntu-12.04
In that case routes to file:
http://mywebsite.com/routes.php?title=how-to-install-wamp-in-ubuntu-12.04
I'm trying to route like the PHP example:
http://mywebsite.com/routes.cshtml?title=how-to-install-wamp-in-ubuntu-12.04
Can I do it in ASP.NET with WebMatrix and razor?
I know how I can take GET data in ASP.NET, but I don't understand how I can make a friendly URL and how I can route to "routes.cshtml" when the page isn't found.

There is an existing package specifically for ASP.NET Web Pages that lets you do what you want and it is available via the WebMatrix Package Manager. It is called Routing For Web Pages. I have written an article on how to use it: http://www.mikesdotnetting.com/Article/187/More-Flexible-Routing-For-ASP.NET-Web-Pages

Details: Microsoft is now making this very easy to do for ASP.NET Via a Nuget Package. Unfortunately, this package "Microsoft.AspNet.FriendlyUrls" is currently in Pre-Release and WebMatrix doesn't allow you to download Pre-Releases. As a result, following my way of doing it might not be as easy compared to if you just had Visual studio or VS Express.
My suggestion is to download Visual Studio Express 2012 and either use that for developing or just use it so you can get Nuget Packages.
Ill assume that you want to develop in WebMatrix.
Solution:
Download and Install Visual Studio Express 2012.
Create a new Website
In solution Explorer, right click on your Website and select "Manage Nuget Packages.."
Press the drop down that says "Stable Only" and choose "Include Prerelease"
In the search box enter "Microsoft.AspNet.FriendlyUrls"
Select "Install"
Open your project in Windows Explorer so you can see all the files.
Copy the folders "App_Code" and "bin" into your WebMatrix Project (e.g. Add them to your solution).
Add a Global Application Class "Global.asax"
In the Application_Start method add the following line
RouteConfig.RegisterRoutes(System.Web.Routing.RouteTable.Routes);
You will now have FriendlyURL's
I know this seems like a lot of work but if you had Visual Studio or WebMatrix allowed Pre-Released then it would be very easy to follow.
Warning: If you do decide to develop it in Visual studio delete the following files as the Mobile part of it doesn't work currently (Hence why it is Pre-Release)
Site.Mobile.Master
LiSite.Mobile.Master.designer.cs
ViewSwitcher.ascx
ViewSwitcher.ascx.designer.cs
Future: In the near future there will be release version of FriendlyUrl's and then you will be able to get it from Nuget in WebMatrix much more easier.
Links To More Information:
Information on Microsoft's Friendly Url Package
Information on how to use Nuget in WebMatrix

of course you can, it is called URL Rewriting
http://developer.mindtouch.com/en/kb/Installing_MindTouch_Core_on_Windows_%28IIS%29/Rewrite_web.config_for_IIS7
or here
http://www.phpgenious.com/2010/04/url-rewriting-with-php-and-iis-7/
or google for more info

Related

Web Deployment Project on VS2019

I've created a blank solution in VS2019. Using the option "add existing web site" I've added a website to the solution which was built in VS2010. Normally, after that, I was used to add a Web Deployment Project to the solution, to compile all the code in one dll, and upload the result to the web server.
But this kind of project does not seem to be compatible anymore with the newer versions of VS.
Is there any way to get a similar compiled result in VS2019?
I found an alternative.
It is to convert the [asp.net web site] to an [asp.net application]. The asp.net application has a publish feature, which can be used to generate an output folder with the compiled application inside, with the aspx pages and a single dll.
I suggest to follow the steps described here to convert the asp.net web site to asp.net application:
https://learn.microsoft.com/en-us/previous-versions/aa983476(v=vs.140)

what kind of asp project was it created with

I am looking to make a change to a web site connected to an SQL server.
as far as I could look at the source files the web page is made in asp with VB (*.aspx, *.aspx.vb, *.ascx, *.ascx.vb - among the file extensions). the issue I am having is that I don't know how was the project created nor which versions were used.
was it a simple web site? or ASP.NET web application? which .netframework version? was it visual studio 2008 or 2010?
the code has no comments anywhere, so it doesn't help me at all.
I tried getting in contact with the previous developer, but he is no longer working in the company. besides the page was created some years ago.
is there a way to recreate the project? anywhere I can look and "guess" which versions I need?
any help is welcome!
Two options.
There is a *.vbproj file among others. This would be a VB.NET VS project file. You can access the project from the VS by opening the project file.
There is no *.vbproj file among others. This would be a VB.NET web site. You can access it by opening it as a "web site" from the VS menu.
The latest version of VS should be able to open any project created with any previous version, in a "worst" case the project would just be converted. I would not be worry about the version of the framework. Plus, if it is a web site, it could be difficult to determine which exact version of VS was used to create it.

visual studio no asp.net possibility

so i just installed microsoft visual studio express 2012 for windows 8 (virtual machine) and i noticed there is no option of creating .asp files
normally, i should be able to file -> new web site, c#, empty. And then add a new web form to create an aspx file, but i dont get these options.
i only get file -> new project which creates javascript (javascript) or XAML files (visual basic, visual C#, visual C++)
i assume there is something wrong with installation. i tried installing ASP.NET from the asp.net website but doesnt change anything.
please hold in mind i am a beginner,
any help is much appreciated
You need this one; sounds like you downloaded the WPF version http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-for-web
You must install the web version to do asp.net.
Check this MSDN

Can't find the Publish Website Option in Visual Studio 2012 Express Web

I created an Empty Website (not a project) using File > New Website > Aps.net Empty Web Site. Usually when I click on Build, there is an option to "Publish Web Site". However, I don't see it here. All I can see is build and rebuild solution. What am I doing wrong? Even when I right click on the website, it just gives me an option to Build, but not Publish. I previously was using VS 2010, and it has the Publish option.
Publishing is only support for web application projects, not web site projects.
http://msdn.microsoft.com/en-us/library/dd547590.aspx
I don't know if this is true in all cases, but I just uninstalled VS 2012 Web Express, deleted the contents in the Microsoft Visual Studio 11 folder, and then installed the Professional version instead. Maybe the Express version doesn't have this, but after installing the Professional version, I do have the "Publish Web Site" option.
I believe this problem can be solved by downloading and installing the relevant Web Publish Update from this web page:
http://msdn.microsoft.com/library/jj161045
I had the same problem in Visual Web Developer 2010 Express. When I installed the update, the option to "Publish Web Site" became available to me.
EDIT: You may find that when you click "Publish Web Site", you get an error like this:
the imported project "C:\ProgramFiles\MSBuild\Microsoft\VisualStudio\v11.0\WebSites\microsoft.website.publishing.
targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
I solved this problem by going into "website.publishproj" (found in the Solution Explorer with my website open), and "hardwiring" the WebPublishTargetsVersion element like this:
<WebPublishTargetsVersion>10.5</WebPublishTargetsVersion>
For some reason, the existing code was returning 11.0, instead of 10.5.
Hardwiring it like this might cause problems later if you update your version. So do it with caution.

visual studio 2010 setup project - shortcut to web page

Is there anyway to create a web link without using custom action?
I want to add a web link to start menu that will open default browser on target machine and browse the link.
A solution is to use IniFile table like in this post.
Visual Studio setup projects do not support this, so you will need to edit your MSI with Orca. A simpler approach is to use WiX or a different setup authoring tool which offers more control over your MSI package.
What I ended up doing was adding the .url file to SetupProject and it did the trick (as it described in the post #Cosmin Pirvu referenced to).

Resources