我的解决方案中有多个 ASP.NET 网站以及一个常见的 C# 代码项目。内容如下:
- Website1
- Website2
- ...
- Website(n)
- Common
首先我想使用 Global.asax 文件来记录所有未处理的异常。我可以为每个网站拥有一个 Global.aspx 文件,但所有代码都是相同的,并且必须保持同一文件的多个副本最新似乎毫无意义。有没有办法将 Global.aspx 文件放在公共库中,然后从每个网站链接到它。我尝试过添加退出项目>添加为链接,但页面不会运行它。
其次,所有网站都需要一个错误页面,我可以在其中写入信息(不仅仅是一个简单的 html 页面),因此我有一个 Error.aspx 页面,我想将其与错误详细信息一起重定向到。同样,我可以每个网站都有一个,但它会是同一个页面。有没有办法可以将其存储在公共项目中并链接到它?到目前为止,我能想到的唯一解决方案是建立一个包含错误页面的错误网站。
I have several ASP.NET websites in a solution along with a common C# code project. Something as follows:
- Website1
- Website2
- ...
- Website(n)
- Common
First off I want to use a Global.asax file to log all unhandled exceptions. I could have one Global.aspx file per website but all the code will be the same and it seems pointless having to keep multiple copies of the same file upto date. Is there a way to have the Global.aspx file in the Common library and then link to it from each website. I have tried doing Add Exiting Item > Add as Link but it doesn't get run by the page.
Secondly all the websites need an Error page which I can write information to (not just a simple html page) so I have an Error.aspx page which I want to redirect to along with the error details. Again I could have one per website, but its going to be the same page. Is there a way I can store this in the Common project and link to it? The only solution so far for this I can think of is to have an Error website which has the Error page in it.
发布评论
评论(1)
您可以从基类继承 Global.asax 文件。所以你的 global.asax 可能看起来像这样:
然后你的 Global.asax.cs 看起来像这样:
在你的库中定义:
就你的“全局”错误页面而言,我要做的是创建一个处理程序(. ashx)每个网站上的页面,然后制作一个库方法来显示您的错误信息。像这样的东西 (Error.ashx)
注意:为了清楚起见,示例中未包含命名空间。
You can inherit your Global.asax file from a base class. So your global.asax might look like this:
Then your Global.asax.cs would look something like this:
In your library define:
As far as your "global" error page is concerned, what I would do is create a handler (.ashx) page on each website and then make a library method to display your error information. Something like this (Error.ashx)
Note: Namespaces not included in example for clarity.