Solved

Url in c# razor webpage

Posted on 2014-10-03
9
142 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 74

Expert Comment

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

Author Comment

by:bongii
Comment Utility
Web Site project
0
 
LVL 74

Expert Comment

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

Screenshot
0
 

Author Comment

by:bongii
Comment Utility
Yes :)
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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
Comment Utility
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 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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
Comment Utility
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 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now