数据库驱动的 asp.net MVC 应用程序

发布于 2024-10-16 02:11:59 字数 1016 浏览 5 评论 0原文

我有一个用经典 ASP(不是 .net)编写的 CRUD 应用程序,它使用负载平衡器 DLL 将页面请求传输(路由)到相关服务器。

它的工作原理如下:

  1. 有人请求 www.mywebsite.com/products

  2. 那里是 products 文件夹下的 index.asp,它将请求重定向到:

    http://www1.mywebsite.com/products
    

    http://www2.mywebsite.com/products
    

    基于负载均衡器逻辑。

另一种情况:

  1. 有人请求 www.mywebsite.com/products/details

  2. products 文件夹中的子文件夹 details 下有一个 index.asp,它将请求重定向到:

    http://www1.mywebsite.com/products/details
    

    http://www2.mywebsite.com/products/details
    

    基于负载均衡器逻辑

应用程序的主要问题是每当我包含新页面时,我需要创建一个文件夹和 index.asp 页面来重定向页面。

我们有一个 CMS 数据库,其中包含所有页面的详细信息。所以我想创建一个 MVC 应用程序来替换现有的经典 ASP 应用程序。

但我没有找到任何数据库驱动的 MVC 应用程序,而且我对路由有点困惑。我是否需要为我拥有的每个主文件夹创建单独的路由,或者应该为所有页面创建通用路由。

任何帮助将不胜感激。

I have a CRUD application written in Classic ASP (not .net) which transfers (routes) page requests to relevant servers using a loadbalancer DLL.

It works like this:

  1. Someone requests for www.mywebsite.com/products

  2. There is an index.asp under folder products that redirects the request to either:

    http://www1.mywebsite.com/products
    

    or

    http://www2.mywebsite.com/products
    

    based on a loadbalancer logic.

Another scenario:

  1. Someone requests for www.mywebsite.com/products/details

  2. There is a index.asp under the sub folder details within the products folder that redirects the request to either:

    http://www1.mywebsite.com/products/details
    

    or

    http://www2.mywebsite.com/products/details
    

    based on loadbalancer logic

The main issue with application is whenever I include a new page, I need to create a folder and index.asp page to redirect the page.

We have a CMS database which contains the details of all pages. So I want to create an MVC application to replace the existing Classic ASP application.

But I didn't find any database driven MVC applications and I'm bit confused by routing. Do I need to create a separate route for each main folder I have or should I create a generic route for all pages.

Any help would be appreciated.

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

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

发布评论

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

评论(3

幸福还没到 2024-10-23 02:11:59

您不必仅仅为了 URL 重写而迁移到 ASP.NET MVC。

IIS 7 确实有一个集成的 URL 重写模块,ASP.NET 4 也包括路由。

无论如何,如果您搜索例如Codeplex 对于 ASP.NET MVC 项目,您会发现其中很多都是数据库驱动的。

您不需要为每个单独的项目创建单独的路线。考虑一下查询字符串 (?id=15&day=monday) 的概念。 URL 重写几乎是一样的。

更新

我发现您正在谈论经典 ASP。

IIS 7 中内置的 URL 重写模块也可以与经典 ASP 配合使用。如果您使用的是较旧的 IIS 版本,则需要第 3 方 ISAPI 重写模块< /a>.

无论如何,将其切换到 ASP.NET MVC ;)

You don't have to migrate to ASP.NET MVC just for the URL rewriting.

IIS 7 does have an integrated URL rewrite module and ASP.NET 4 includes routing as well.

Anyhow, if you search e.g. on Codeplex for ASP.NET MVC projects, you'll find a lot of them which are database driven.

You don't need to create individual routes for each seperate item. Think about the concept of querystrings (?id=15&day=monday). URL rewriting is pretty much the same.

Update

I've overseen that your talking about classic ASP.

The build in URL rewrite module in IIS 7 works also fine with classic ASP. If you are having an older IIS version you need a 3rd party ISAPI rewrite module.

Anyhow, switch it to ASP.NET MVC ;)

风吹雨成花 2024-10-23 02:11:59

MVC 非常适合解决您的路由问题。 ASP.NET 4 也是如此。

但是,您遇到的问题是您的了解不够,无法提出精确的问题。因此,您对 MVC 中的路由感到困惑。

因此,我建议阅读 nerddinners 教程。您可以免费下载 PDF 文件。要更进一步,请阅读 Stephen Sanderson 的有关 MVC 2(或几个月后的 MVC3)的书。

如果您遵循 nerddinners 教程和 Stephen Sanderson 的教程,这将使您更好地了解它是如何工作的。

简而言之,这就是 MVC 的工作原理:

在 MVC 中,您会忘记文件和文件夹。

相反,您有控制器和操作。路由将请求映射到正确的控制器和操作。

然后,操作中的代码决定哪个视图填充数据(来自数据库或其他地方,这并不重要)。视图只是被告知要做什么以及要显示什么数据的模板。

控制器向模型询问他们想要的数据。

即,数据访问全部在模型中完成,与用户界面巧妙地分开。

中号:型号
五:观点
C:Controller

上面的内容对你来说可能毫无意义。这是与经典 ASP 非常不同的思维方式。

如果您来自旧的 ASP,您将需要长途跋涉,但这是可以完成的。我来自Access。无论如何,请阅读书籍,按照教程进行操作,看看它是否适合您。

当您准备好时,我们仍然会在这里帮助您解决更精确的问题。

MVC would lend itself very well to sorting your routing problem. So would ASP.NET 4.

However, the problem you have is that you don't know enough to ask a precise question. Hence your confusion with routing in MVC.

I would therefore suggest reading the nerddinners tutorial. You can get a PDF download for free. To go a step further, read Stephen Sandersons book on MVC 2 (or MVC3 in a couple of months).

If you follow the nerddinners tutorial and Stephen Sanderson's tutorial, that will give you a better idea of how it works.

In short, this is how MVC works:

In MVC, you forget about files and folders.

Instead, you have Controllers and actions. The routes map the requests to the right controller and action.

The code in the actions then decide which View to stuff full of data (from a database or wherever, it doesn't matter). The Views are just templates that are told what to do and what data to display.

The Controllers ask the Model for the data that they want.

Ie, the data access is all done in the Model, neatly separated from the User Interface.

M: Model
V: Views
C: Controller

The above is probably meaningless to you. It is a VERY different mindset to ASP classic.

If you are coming from old ASP, you will have a long hike, but it can be done. I came from Access. Anyway, read the books, follow the tutorial and see if it is for you.

When you are ready, we will still be here to help with more precise questions.

夏夜暖风 2024-10-23 02:11:59

迁移的应用程序中的 Asp.net MVC 路由

根据您在此处显示的请求,您可以仅使用默认路由对所有内容进行排序:

{controller}/{action}/{id}

在您的情况下,您将拥有一个包含您需要的所有操作的 ProductsController

负载平衡应用程序

但是拥有一个 Asp.net MVC 应用程序只是其中的一部分。该应用程序将在两台负载平衡服务器上运行。所有重定向都应在访问 MVC 应用程序之前完成。

如果您打算继续使用相同的负载平衡器 DLL,您可以创建一个不同的 Asp.net MVC 应用程序,仅使用一个路由定义:

{*path}

以及一个控制器和操作来完成这一切:

public Load: Controller
{
    public ActionResult Balance(path)
    {
        // decide for web server and attach path to subdomain
    }
}

只要这个动作很小。否则,您的负载平衡逻辑将成为应用程序的瓶颈,因为所有请求都会经过此负载平衡器(它现在也这样做,因此请记住,现在没有什么不同;不用介意您可能使用的不同子域上的身份验证过程) 。

负载平衡替代方案

您应该考虑使用 IIS 7 上的 Web 场平衡功能,该功能将在多个 Web 服务器上运行您的应用程序(因为这就是负载平衡首先要做的事情)。在网络上搜索网络场信息。您可以从以下开始:

http://www.iis.net/download/webfarmframework

Asp.net MVC routing in your migrated application

Based on requests you've shown here you can sort everything up with just default route:

{controller}/{action}/{id}

In your case you'd have a ProductsController with all the actions you need.

Load balancing application

But having an Asp.net MVC application is just one part. This application will run on both load balanced servers. All redirecting should be done before they hit the MVC application.

If you intend to continue using the same loadbalancer DLL you could create a different Asp.net MVC application with only one route definition:

{*path}

and a single controller and action that does it all:

public Load: Controller
{
    public ActionResult Balance(path)
    {
        // decide for web server and attach path to subdomain
    }
}

This should do the trick just fine as long as the overhead of this action is very small. Otherwise your load balancing logic will become the bottleneck of your application since all requests go through this load balancer (it does that now as well so bare in mind this is no different now; never mind the authentication process on different subdomains you may be using).

Load balancing alternative

You should consider using the web farm balancing capabilities on the IIS 7 that will run your application on several web servers (because that's what your load balancing does in the first place). Search the web for web farm information. You can start with this:

http://www.iis.net/download/webfarmframework

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