【问题标题】:Issue with links using page routing使用页面路由的链接问题
【发布时间】:2013-01-25 13:42:03
【问题描述】:

我正在使用RouteTable 为我的站点注册一些路由。现在,它看起来像这样:

Global.asax

void Application_Start(object sender, EventArgs e)
{    
    RemoteReaderPlugin.Current.AllowRemoteRequest += Current_AllowRemoteRequest;

    RegisterRoutes(RouteTable.Routes);
}

public static void RegisterRoutes(RouteCollection routes)
{
    //routes.Ignore("{resource}.axd/{*pathInfo}");

    //Clan
    routes.MapPageRoute("","Clan/{address}","~/Clan/Default.aspx");
    routes.MapPageRoute("", "Clan/Register", "~/Clan/Register.aspx");
    routes.MapPageRoute("", "Member/GameRanking/{address}", "~/Member/GameRanking.aspx");

    //Member
    routes.MapPageRoute("", "Member/{address}", "~/Member/Default.aspx");
    routes.MapPageRoute("", "Member/Register", "~/Member/Register.aspx");
    routes.MapPageRoute("", "Member/GameRanking/{address}", "~/Member/GameRanking.aspx");

    //Site
    routes.MapPageRoute("", "{address}", "~/{address}.aspx");
    routes.MapPageRoute("", "{address}/{resource}", "~/{address}/{resource}.aspx");
}

当我将浏览器指向http://localhost:27950/OCDB/Default时,这一切都有效。

但是,当我将浏览器指向http://localhost:27950/OCDB/ 时,我点击的任何链接都会导致此错误:

Server Error in '/OCDB' Application.

The HTTP verb POST used to access path '/OCDB/' is not allowed.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: The HTTP verb POST used to access path '/OCDB/' is not allowed.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[HttpException (0x80004005): The HTTP verb POST used to access path '/OCDB/' is not allowed.]
   System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state) +2523961
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18034

有什么办法可以解决这个错误吗?或者强制浏览器使用/Default

【问题讨论】:

    标签: c# asp.net routes


    【解决方案1】:

    如果你替换这一行会发生什么:

    routes.MapPageRoute("", "{address}", "~/{address}.aspx");
    

    routes.MapPageRoute("", "{address}", "~/{address}.aspx", true, defaults: new RouteValueDictionary { { "address", "default" } });
    

    希望这会有所帮助

    【讨论】:

      猜你喜欢
      • 2019-03-22
      • 1970-01-01
      • 2020-06-02
      • 2019-11-24
      • 1970-01-01
      • 2021-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多