在 asp.net mvc 中路由 webform

发布于 2024-09-12 21:20:49 字数 440 浏览 5 评论 0原文

我有一个 ASP.NET MVC 应用程序,并且有一个在 MVC 中构建的 WebForm 页面,因为有一个关于如何做我需要做的事情的教程,但它都是 WebForm 风格的。我试图弄清楚如何以 MVC 格式做同样的事情,但无法弄清楚。所以我需要弄清楚如何在我的 MVC 应用程序中使用此页面。但是,当我尝试转到该页面时,它给出错误“页面不能从 ViewMasterPage 派生,除非页面从 ViewPage 派生。”所以我还必须制作一个新的标准 MasterPage。

情况是这样的。我有一个位于 MVC ViewMasterPage 中的搜索栏,该搜索栏位于从它派生的每个页面上。用户在搜索栏中提交信息后,它会调用 WebForm Search.aspx 页面并在 Search.aspx 页面上显示结果。我希望 URL 类似于“http:///search//。Search.aspx 页面位于项目的根目录中。我如何获得我正在寻找的结果?谢谢!

I have an ASP.NET MVC app and I have a WebForm page I built in the MVC due to a tutorial on how to do something I needed to do, but it was all in WebForm style. Ive tried to figure out how to do the same thing in MVC format but cant figure it out. So I was needing to figure out how to use this page in my MVC app. But when I try to go to the page, it gives me the error "Page cannot be derived from ViewMasterPage unless Page derives from ViewPage." So I had to make a new standard MasterPage also.

The situation is this. I have a search bar located in the MVC ViewMasterPage thats on every page that is derived from it. Once a user submits info in the search bar, it calls the WebForm Search.aspx page and displays the results on the Search.aspx page. I want the URL to be like "http:///search//. The Search.aspx page is located in the root of the project. How would I get the results Im looking for? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寂寞笑我太脆弱 2024-09-19 21:20:49

您可能想要在正确的 MVC 中重新实现该 Web 表单。如果您知道自己在做什么,那么两者可以在同一个 Web 应用程序中很好地协同工作,但是如果您尝试在 MVC 中实现整个事情,那么只坚持偶尔使用页面的 Web 表单教程可能会有所帮助。整个事情变得更加难以支持。 (正如您已经从必须制作第二个母版页中学到的那样。)

学习教程,但要重点了解他们正在做什么,而不仅仅是复制/粘贴代码。您端的实际实现听起来应该保留在 MVC 中。

You're probably going to want to re-implement that web form in proper MVC. The two can play nice together in the same web app if you know what you're doing, but if you're trying to implement the whole thing in MVC then just sticking with a web forms tutorial for the occasional page is probably going to make the whole thing a lot more difficult to support. (As you've already learned from having to make a second master page.)

Study the tutorials, but make it a point to learn exactly what it is they're doing rather than just copy/paste the code. The actual implementation on your end sounds like it should stay in MVC.

白首有我共你 2024-09-19 21:20:49

ASP.NET WebForms 绝对可以处理路由。我最近构建了一个非常大的网站,它完全是 WebForms 且完全路由的。除了 Viewstate 和其他形式垃圾之外,没有公开迹象表明它是一个 aspx 站点。

<system.webServer>
  <rewrite>
    <rules>
      <!-- If a user requests the search.aspx page, redirect them to /search -->
      <rule name="Search-Redirect" stopProcessing="true">
        <match url="^search\.aspx$" />
        <conditions>
          <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
        </conditions>
        <action type="Redirect" url="search" appendQueryString="true" />
      </rule>
      <!-- If a user requests the search page with a query appended to the URL, send them to the search.aspx page and put the training URL into the q query string -->
      <rule name="Search-Query-Rewrite" stopProcessing="true">
        <match url="^search/([_0-9a-z-]+)" />
        <action type="Rewrite" url="search.aspx?q={R:1}" appendQueryString="false" />
      </rule>
      <!-- If a user requests the search page without a query appended, just send them to the search.aspx page -->
      <rule name="Search-Rewrite" stopProcessing="true">
        <match url="^search$" />
        <action type="Rewrite" url="search.aspx" />
      </rule>
    </rules>
  </rewrite>
</system.webServer>

您可能需要稍微调整一下,具体取决于您的 URL 结构、您打算如何让搜索条件进入页面,但它会起作用。

ASP.NET WebForms can absolutely handle the routing. I've recently built a very large site that is completely WebForms and completely routed. There is no public indication that it is an aspx site other than Viewstate and the other tell-tale form garbage.

<system.webServer>
  <rewrite>
    <rules>
      <!-- If a user requests the search.aspx page, redirect them to /search -->
      <rule name="Search-Redirect" stopProcessing="true">
        <match url="^search\.aspx$" />
        <conditions>
          <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
        </conditions>
        <action type="Redirect" url="search" appendQueryString="true" />
      </rule>
      <!-- If a user requests the search page with a query appended to the URL, send them to the search.aspx page and put the training URL into the q query string -->
      <rule name="Search-Query-Rewrite" stopProcessing="true">
        <match url="^search/([_0-9a-z-]+)" />
        <action type="Rewrite" url="search.aspx?q={R:1}" appendQueryString="false" />
      </rule>
      <!-- If a user requests the search page without a query appended, just send them to the search.aspx page -->
      <rule name="Search-Rewrite" stopProcessing="true">
        <match url="^search$" />
        <action type="Rewrite" url="search.aspx" />
      </rule>
    </rules>
  </rewrite>
</system.webServer>

You might need to tweak this a little depending up your URL structure, how you intend for the search criteria to come into the page, but it will work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文