简体   繁体   English

无法使用URL参数将ASPX页面重定向到.NET MVC 4中的控制器

[英]Can't redirect aspx page to controller in .NET MVC 4 with url param

I'm trying to redirect requests made to an .aspx page to a controller in my MVC 4 .NET application. 我试图将对.aspx页的请求重定向到我的MVC 4 .NET应用程序中的控制器。 Actually, I have a parameter passed via GET to the URL like this: 实际上,我有一个通过GET传递给URL的参数,如下所示:

myPage.aspx?param1=helloworld

In my controller, I have the following action 在我的控制器中,我执行以下操作

class MyController : Controller
{
    public void MyAction(string param1)
    {
        [...]
    }
}

In RouteConfig.cs I've tried the following cases, but any of this options worked. 在RouteConfig.cs中,我尝试了以下情况,但是任何此选项均有效。 I can't find information about how to pass url encoded GET paramters. 我找不到有关如何传递URL编码的GET参数的信息。 (Also I got a 404 error if I try to access the aspx page without parameters and redirect to a controller action without parameters. (如果我尝试访问不带参数的aspx页面并重定向到不带参数的控制器操作,也会收到404错误。

    public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        [...]

        routes.MapRoute(
           name: "name",
           url: "myPage.asp.aspx",
           defaults: new { controller = "My", action = "MyAction", param1 = "defaultValue" }
        );

        routes.MapRoute(
           name: "name",
           url: "myPage.asp.aspx{value}",
           defaults: new { controller = "My", action = "MyAction", param1 = "defaultValue" }
        );


       routes.MapRoute(
           name: "name",
           url: "myPage.asp.aspx?value={value}",
           defaults: new { controller = "My", action = "MyAction", param1 = "defaultValue" }
        );


    }
}

How can I get this working (I explicity need to pass de value in the URL in that form) 我如何才能正常工作(我需要以这种形式在URL中明确传递值)

Thanks 谢谢

In myPage.aspx: 在myPage.aspx中:

Response.Redirect("http://www.someMVC4site.com/my/MyAction/helloworld");

In RouteConfig.cs of MVC4 project 在MVC4项目的RouteConfig.cs中

routes.MapRoute(
       name: "name",
       url: "{controller}/{action}/{param1}",
       defaults: new { controller = "My", action = "MyAction", param1 = "defaultValue" }
    );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM