Solved

Url in c# razor webpage

Posted on 2014-10-03
9
147 Views
Last Modified: 2014-10-03
Hi.

I want my page to have the urlstructure like this:
www.domain.com
www.domain.com/categoryname
www.domain.com/categoryname/product
how does it work. It seems like there need to be a psyical file like:
www.domain.com/category/catogoryname
www.domain.com/product/productname
where category and product is .cshtml files.
0
Comment
Question by:bongii
  • 5
  • 4
9 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40359301
Are you writing a Web Forms or MVC application (or a Web Site project)?
0
 

Author Comment

by:bongii
ID: 40359302
Web Site project
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40359308
Just to be absolutely sure:  When you say "Web Site", you created your project like this, yes?

Screenshot
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:bongii
ID: 40359328
Yes :)
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40359418
Well Web Sites don't use the routing engine that MVC comes with, so they more or less work like traditional web pages. Short of writing your own custom module, or *maybe* importing one of the MVC modules, I think URL rewriting would probably be the easiest route to go. I would start at the official ASP.NET web site for more information:

http://www.iis.net/learn/extensions/url-rewrite-module

The gist of it will be that you put your simplified URLs in your Razor--probably by hand rather than through the default helpers; or perhaps you can write a helper--and you set up your rewrites to manipulate these URLs into what the web server expects to see.
0
 

Author Comment

by:bongii
ID: 40359424
Ok. I´ve tried in global asa, but gets an error:  
Mente du: Typen 'ASP.Page Default Cshtml' nedarves ikke fra 'System.Web.UI.Page'.
Type 'ASP._Page_default_cshtml' not inherited from 'System.Web.UI.Page'.


void Application_Start(object sender, EventArgs e)
    {
        RegisterRoutes(RouteTable.Routes);
    }

    void RegisterRoutes(RouteCollection routes)
    {
        // redirects
        routes.MapPageRoute("hello", "hello", "~/default.cshtml");
    }
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40359450
I don't think that will work because you're attempting to mix MVC and Web Site architectures. It may, but I wouldn't know where to begin in order to make it work. Someone else might.
0
 

Author Comment

by:bongii
ID: 40359466
Ok. So it´s not possible to make the routes to files in folders?
It only work if the name is a file in main path?
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 40359467
I'm saying that I don't believe you can use anything to do with routes because you are not working in an MVC project.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question