0

I have ASP.NET webFroms application on my local, when i try to use this following rout I get 404 not found error. I am trying to go to mylocalsite.com/home that should resolve to ~/Default.aspx, what can be the issue? I did try many ways and followed on MSDN help on http://msdn.microsoft.com/en-us/library/cc668202.aspx but cant make it to work so that I can create the routs that i need. the site is running on IIS7.

this following code is in my Global.asax

public static void RegisterRoutes(RouteCollection routes)
        {

            routes.MapPageRoute("homepage", "/home", "~/Default.aspx");

        }

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


        }
Nazo Tajrian
  • 131
  • 2
  • 14

3 Answers3

0

A route cannot start with /. Try:

routes.MapPageRoute("homepage", "home", "~/Default.aspx");

Also make sure that your application pool is configured to run in Integrated Pipeline mode in IIS 7.0 in order for extensionless urls such as /home to work.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • I did try without /, but still the same issue, also could you please tell me how should I configure Integrated Pipeline mode in IIS 7? because I did some search and came many ways of configuration on this so not sure which one exactly you mean? – Nazo Tajrian Mar 02 '12 at 01:58
  • @NazoTajrian, take a look here: http://technet.microsoft.com/en-us/library/dd441157(v=office.13).aspx – Darin Dimitrov Mar 02 '12 at 06:54
  • Hey Darin, yes I thing this is one of my issues, I have my application in classic pipeline mode but when I switch to Integrated I get an error: HTTP Error 500.22 - Internal Server Error An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode. I think the issue is related to web.config maybe? I am currently searching for this error Error 500.22 but meanwhile if you know any about this can you tell me? or any suggestions how to fix to run on Integrated mode? – Nazo Tajrian Mar 02 '12 at 16:06
  • @NazoTajrian, which setting is the error referring to? Be aware that in integrated pipeline mode you don't have access to an HttpContext in the Application_Start method so any attempt to access some of its properties might fail. – Darin Dimitrov Mar 02 '12 at 17:14
  • Hi, yes that was the issue in my Application_Start but what will be alternative of Application_Start to use if there is? I was just loading some files from folder in Application_Start – Nazo Tajrian Mar 02 '12 at 18:36
  • @NazoTajrian, you can use Application_Start in integrated mode. What you cannot use is access to HttpContext. Depending on what exactly are you trying to achieve there are alternatives. You mention something about files, so I guess you are trying to find the physical location to those files. So instead of for example using `Server.MapPath` you could use `HostingEnvironment.ApplicationPhysicalPath` to get the root physical path of your site and from there `Path.Combine` to reach the desired location. – Darin Dimitrov Mar 02 '12 at 19:30
  • I made my application to work in Integrated mode and just for now commented all of my code in Application_Start i can figure that out later no problem, I have my route setup as : routes.MapPageRoute("homepage", "home", "~/Default.aspx"); but still can't make this route to work, I still get "HTTP Error 404.0 - Not Found" error when i goto mylocalsitename.com/home by the way this is hosted on my local – Nazo Tajrian Mar 03 '12 at 03:24
  • By the way, i did try one thing and it worked, I created new ASP.NET Application project in VS2010 and added the same route there then I did right click on default.aspx to run in browser which will creat visual development server like http://localhot:xxxx/ and this way the routing worked good, so the only differences is that the application I have the routing is not working if is setup on IIS but it is working if I run from visual studio what will the reason can be for this to act like that? thanks. – Nazo Tajrian Mar 03 '12 at 17:11
0

Second argument to MapPageRoute method is The URL pattern for the route, which is the path that you see after server/application name, you should not specify "/" for it.

DotNetUser
  • 6,494
  • 1
  • 25
  • 27
0

thanks for all of your help, and I finally found what was my exact problem, you can see it in below link, my main issue was HTTP Redirection feature was not enabled in windows features --> World wide web Services --> Common HTTP Features --> HTTp Redirection

full steps for fix: ASP.NET 4.0 URL Routing HTTP Error 404.0 - Not Found

Community
  • 1
  • 1
Nazo Tajrian
  • 131
  • 2
  • 14