Solved

Url in c# razor webpage

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

Author Comment

by:bongii
ID: 40359328
Yes :)
0
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.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

26 Experts available now in Live!

Get 1:1 Help Now