ASP.NET 4.0 Url Routing Błąd HTTP 404.0-nie znaleziono
Zaimplementowałem routing URL w ASP.NET 4.0 korzystanie z następującej trasy.
routes.MapPageRoute(
"NewsDetails", // Route name
"news/{i}/{*n}", // Route URL
"~/newsdetails.aspx" // Web page to handle route
);
Co daje mi url jak
http://www.mysie.com/news/1/this-is-test-news
I to działa w moim localhost grzywny.
Ale jak wgrałem go na serwer to daje ...
Server Error
404 - File or directory not found.
The resource you are looking for might have been removed, had its name changed,
or is temporarily unavailable.
If I try http://www.mysie.com/news/1/this-is-test-news.aspx następnie wyświetla stronę.
Czy ktoś ma ten sam problem?Jak mogę ustawić URL http://www.mysie.com/news/1/this-is-test-news do pracy nad windows server 2008 ?
3 answers
Aby włączyć domyślną ASP.Net 4.0 routing z IIS 7.5:
- Upewnij się, że masz zainstalowaną funkcję przekierowania HTTP Można to zrobić - > Panel sterowania -> Progams -> wyłącz funkcje systemu windows -> World wide web Services -> wspólne funkcje HTTP - > przekierowanie HTTP
- zmodyfikuj swoje
web.config
z poniższym kodem
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="UrlRoutingModule"/>
<add name="UrlRoutingModule"
type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
<handlers>
<add name="UrlRoutingHandler"
preCondition="integratedMode"
verb="*"
path="UrlRouting.axd"
type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</handlers>
</system.webServer>
3. Tworzenie tras w pliku global.asax
Mam nadzieję, że to pomoże.Uwaga: Należy ustawić pulę aplikacji na Asp.net 4, 0 pula aplikacji , ponieważ routing nie działa z Asp.net 4.0 Klasyczna pula aplikacji.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-06-25 11:44:14
Przeczytałam wszystkie twoje przepisy, ale moja strona ( ASP.NET 4.0 + VS2010 + Cassini) nadal nie było routingu poprawnie.
Wirtualna ścieżka dla mojej strony to "nazwa firmy.Nazwa aplikacji.Www". Zmieniłem ten wirtualny na "My ApplicationName" i voila!
Zmień konfigurację ścieżki wirtualnej Cassini:
- wirtualna ścieżka Cassiniego - > Ctrl + W, P or;
- kliknij prawym przyciskiem myszy witrynę internetową i "okno Właściwości".
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-11-07 17:13:03
Moje rozwiązanie, po wypróbowaniu wszystkiego:
Złe wdrożenie, stara wstępnie skompilowana aplikacja.config kręcił się wokół mojej lokalizacji wdrożenia i sprawiał, że wszystko nie działało.
Moje ostatnie ustawienia, które zadziałały:
- IIS 7.5, Win2k8r2 x64,
- Integrated mode application pool
-
w sieci nic się nie zmienia.config - oznacza to brak specjalnych uchwytów do routingu. Oto moja migawka sekcji wiele innych wpisów odniesienia. Używam FluorineFX, więc mam ten handler dodany, ale nie potrzebowałem żadnych innych:
<system.web> <compilation debug="true" targetFramework="4.0" /> <authentication mode="None"/> <pages validateRequest="false" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/> <httpRuntime requestPathInvalidCharacters=""/> <httpModules> <add name="FluorineGateway" type="FluorineFx.FluorineGateway, FluorineFx"/> </httpModules> </system.web> <system.webServer> <!-- Modules for IIS 7.0 Integrated mode --> <modules> <add name="FluorineGateway" type="FluorineFx.FluorineGateway, FluorineFx" /> </modules> <!-- Disable detection of IIS 6.0 / Classic mode ASP.NET configuration --> <validation validateIntegratedModeConfiguration="false" /> </system.webServer>
-
Globalny.ashx: (only method of any note)
void Application_Start(object sender, EventArgs e) { // Register routes... System.Web.Routing.Route echoRoute = new System.Web.Routing.Route( "{*message}", //the default value for the message new System.Web.Routing.RouteValueDictionary() { { "message", "" } }, //any regular expression restrictions (i.e. @"[^\d].{4,}" means "does not start with number, at least 4 chars new System.Web.Routing.RouteValueDictionary() { { "message", @"[^\d].{4,}" } }, new TestRoute.Handlers.PassthroughRouteHandler() ); System.Web.Routing.RouteTable.Routes.Add(echoRoute); }
-
/ Align = "left" / cs-uzyskało to automatyczną konwersję z http://andrew.arace.info/stackoverflow do http://andrew.arace.info/#stackoverflow {[29] } które następnie byłyby obsługiwane domyślnie.aspx:
public class PassthroughRouteHandler : IRouteHandler { public IHttpHandler GetHttpHandler(RequestContext requestContext) { HttpContext.Current.Items["IncomingMessage"] = requestContext.RouteData.Values["message"]; requestContext.HttpContext.Response.Redirect("#" + HttpContext.Current.Items["IncomingMessage"], true); return null; } }
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-03-17 15:40:45