1

I have a few lines of code that needs to run before the user get redirected to authentication part of my MVC4 Project.

I am using :

<modules>
  <add name="WSFederationAuthenticationModule" type="System.IdentityModel.Services.WSFederationAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />
  <add name="SessionAuthenticationModule" type="System.IdentityModel.Services.SessionAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />
</modules>

and

<authorization>
  <deny users="?" />
</authorization>

The reason for doing this is that I need to add the site to Azure ACS if its not already added and i need to do this before the user is directed to ACS. Where would be the best place to run the code? (I need access to the url its coming from as thats what is needed to be given to ACS, so global.asax is not the right place i guess. (Assuming it can be started without a request coming in).

4

1 回答 1

0

确实,即使在阅读了您希望动态发现域的评论之后,这也应该是 Application_Start 事件的一部分。

您应该在某种文件中拥有所有域的有效列表 - 很可能是 web.config。

出于性能和架构的原因,去 Godaddy 并购买一个新域并将其指向您的站点似乎不是一个可能的过程,不能让您再做 1 个步骤......把它放在配置文件中:)

(根据评论在答案中添加这个......) - 您还可以Hashset<string>在 Global.asax 文件中添加一个私有静态,并在 Application_BeginRequest 检查当前域是否已经注册,如果没有,注册它.

这将为每个请求增加大约 0.001 毫秒的时间,所以这确实很少。

于 2013-05-30T02:26:19.997 回答