Solved

Url in c# razor webpage

Posted on 2014-10-03
9
154 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 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