导致ASP.NET站点自动重启的原因

 

ASP.NET站点有时候会莫名其妙的重启,什么原因导致的却不得而知,经过一番折腾后,我总结了导致ASP.NET站点重启的10个原因

1. 回收应用程序池会导致站点重启,记录的原因是:

HostingEnvironment initiated shutdown HostingEnvironment caused shutdown

2. 修改应用程序池回收规则会导致重启,记录的重启原因:

HostingEnvironment initiated shutdown HostingEnvironment caused shutdown

3. 在IIS中修改站点的名字,不会导致重启

4. 修改站点根目录的配置文件web.config,在配置文件注释中添加几个空格会导致重启,记录的重启原因是:

CONFIG change HostingEnvironment initiated shutdown

但是修改子目录的web.config文件不一定会导致马上重启

5. 修改aspx,master文件不一定会导致重启;但是每修改一次都会导致一次重新编译,重新编译次数达到15次之后会导致站点重启,重启原因是:

Recompilation limit of 15 reached HostingEnvironment initiated shutdown

15次后重启这个数字可以在web.config中做配置,修改compilation的numRecompilesBeforeAppRestart属性值即可。

<compilation debug="false" numRecompilesBeforeAppRestart="15">

6. 删除bin目录下的pdb文件,会导致重启,记录的重启原因是:

Change Notification for critical directories.

在bin目录下新建一个空的文件夹,会导致站点重启,重启原因是:

Directory rename change notification for 'D:projectsTestWebAppTestWeb'.T estWeb dir change or directory rename

在bin目录下删除空文件夹,会导致站点重启,记录原因是:

Directory rename change notification for 'D:projectsTestWebAppTestWeb'.T estWeb dir change or directory rename

7. 修改Global.asax文件会导致站点重启,即使加几个空格也会重启,记录的重启原因是:

Change in GLOBAL.ASAX HostingEnvironment initiated shutdown

8. 对App_Code目录做修改会导致站点重启

在站点根目录下添加一个名字为App_Code的文件夹,会导致重启,记录的重启原因是:

Change Notification for critical directories. App_Code dir change or directory rename

删除App_Code文件夹会导致站点重启,记录的重启原因是:

File Change Notification Error in D:projectsTestWebAppTestWebapp_code

Change Notification for critical directories.

App_Code dir change or directory rename

在App_Code文件夹下面新建或者删除一个cs文件,会导致站点重启,记录的原因是:

Change Notification for critical directories. App_Code dir change or directory rename

9. 对关键路径的修改都会导致站点重启,关键路径包括:

bin, App_Code, Web References,App_Browsers,App_GlobalResources,App_LocalResources

10. 另外杀毒软件对文件的扫描,有可能会导致ASP.NET进程误认为文件或者关键路径发生了变化,也会导致重启。

以上是我总结的导致ASP.NET站点重启的10个原因。 总的来说有三个方面会导致站点重启:一方面是IIS配置发生变化;另一方面是ASP.NET相关文件配置文件,global文件,aspx,ascx,master等类型的文件发生变法;第三个方面是关键路径bin,app_Code, Web References,App_Browsers,App_GlobalResources,App_LocalResources发生变化。

如何记录ASP.NET站点重启的原因呢?

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ASP.NET自动登录(AD自动登录)可以让用户在访问Web应用程序时无需再次输入他们的凭据。它允许用户在他们的计算机上通过Windows身份验证登录,并自动通过ASP.NET应用程序进行身份验证。 以下是实现ASP.NET自动登录(AD自动登录)的步骤: 1. 在Web.config文件中启用Windows身份验证: ``` <authentication mode="Windows" /> ``` 2. 在Global.asax文件中添加以下代码: ``` protected void Application_AuthenticateRequest(Object sender, EventArgs e) { if (HttpContext.Current.User != null) { if (HttpContext.Current.User.Identity.IsAuthenticated) { if (HttpContext.Current.User.Identity is WindowsIdentity) { // Get the Windows identity. var windowsIdentity = (WindowsIdentity)HttpContext.Current.User.Identity; // Get the user name and domain name. var userName = windowsIdentity.Name; var domainName = windowsIdentity.Name.Split('\\')[0]; // Authenticate the user against Active Directory. if (AuthenticateUser(userName, domainName)) { // Create a new identity using the user name and domain name. var identity = new GenericIdentity(userName, "Windows"); // Get the roles for the user from Active Directory. var roles = GetRolesForUser(userName, domainName); // Attach the roles to the identity. HttpContext.Current.User = new GenericPrincipal(identity, roles); } else { // Redirect the user to the login page. FormsAuthentication.RedirectToLoginPage(); } } } } } private bool AuthenticateUser(string userName, string domainName) { // Authenticate the user against Active Directory. // Return true if the user is authenticated, false otherwise. } private string[] GetRolesForUser(string userName, string domainName) { // Get the roles for the user from Active Directory. // Return an array of role names. } ``` 3. 在Web应用程序中创建一个登录页面。 4. 在登录页面中添加以下代码: ``` protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request.IsAuthenticated) { // Redirect the user to the default page. Response.Redirect("~/Default.aspx"); } } } protected void btnLogin_Click(object sender, EventArgs e) { // Authenticate the user against Active Directory. if (AuthenticateUser(txtUserName.Text, txtPassword.Text)) { // Redirect the user to the default page. FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, false); } else { // Display an error message. lblErrorMessage.Text = "Invalid username or password."; } } private bool AuthenticateUser(string userName, string password) { // Authenticate the user against Active Directory. // Return true if the user is authenticated, false otherwise. } ``` 这些步骤将帮助您实现ASP.NET自动登录(AD自动登录)。当用户访问您的Web应用程序时,他们将通过Windows身份验证自动登录,并自动通过ASP.NET应用程序进行身份验证。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值