applicationName 属性实际上是如何工作的?

发布于 2024-10-08 13:50:18 字数 2844 浏览 0 评论 0原文

我只是想知道

为什么 ASP.NET 团队选择 / 作为成员角色应用程序名称的默认值,而不是有意义的项目名称?

此外,该应用程序可能不会部署为根应用程序。这意味着/不再合适。

编辑1:

例如:我先创建一个项目A并部署它。后来我创建了另一个项目B并部署它。如果两个项目都使用默认值,它们仍然可以工作,但很难知道哪些用户来自每个项目。

对我来说,最好将默认值设置为项目名称。

编辑 2:

我正在讨论 Visual Studio 在 Web.config 中生成的 applicationName 属性。 为什么默认情况下不使用项目名称而不是 / ?

<membership>
      <providers>
        <clear />
        <add name="AspNetSqlMembershipProvider"
             type="System.Web.Security.SqlMembershipProvider"
             connectionStringName="ApplicationServices"
             enablePasswordRetrieval="false"
             enablePasswordReset="true"
             requiresQuestionAndAnswer="false"
             requiresUniqueEmail="false"
             maxInvalidPasswordAttempts="5"
             minRequiredPasswordLength="6"
             minRequiredNonalphanumericCharacters="0"
             passwordAttemptWindow="10"
             applicationName="/" />
      </providers>
    </membership>
    <profile>
      <providers>
        <clear />
        <add name="AspNetSqlProfileProvider"
             type="System.Web.Profile.SqlProfileProvider"
             connectionStringName="ApplicationServices"
             applicationName="/" />
      </providers>
    </profile>
    <roleManager enabled="false">
      <providers>
        <clear />
        <add name="AspNetSqlRoleProvider"
             type="System.Web.Security.SqlRoleProvider"
             connectionStringName="ApplicationServices"
             applicationName="/" />
        <add name="AspNetWindowsTokenRoleProvider"
             type="System.Web.Security.WindowsTokenRoleProvider"
             applicationName="/" />
      </providers>

</roleManager>

编辑3:

创建两个应用程序(即,一个作为根应用程序,另一个作为子应用程序)并且两个应用程序都将相同的applicationName设置为/后,两个应用程序使用相同的ApplicationID。这意味着斜杠与站点域树无关。我的困惑得到了解答。那么...为什么 Visual Studio 默认将其设置为 / (这让我感到困惑)?

编辑4:

我有两个应用程序。一个作为根应用程序,另一个作为前者下的子应用程序。两者都使用 applicationName =“/”。我在数据库中得到的结果如下: 那么/是什么意思?如果没有意义,为什么VS选择这个令人困惑的名称而不是项目名称?

alt text

编辑5:

从此文章,我将进行总结:

  1. 如果我们从两个应用程序的 web.config 中删除 applicationName 属性,则在数据库中为根生成的 ApplicationName 将是“ /”,数据库中为子应用程序生成的应用程序名称将为“/subappvirtualdir”。
  2. 如果我们将两个应用程序的 applicationName 保留为其默认值“/”,则根应用程序和子应用程序都将获得数据库中生成的相同的“/”ApplicatonName。
  3. 如果我们将两个应用程序的 applicationName 更改为“您想要的任何名称”,则数据库中生成的应用程序名称将被设置为两个应用程序的“您想要的任何名称”。

感谢 Rockin 提供上面的链接!

I am just wondering

why did asp.net team choose / as the default value of Membership Role application name rather than the project name that makes sense?

In addition, the application might not be deployed as the root application. It means that / is no longer appropriate.

Edit 1:

For example: I create a project A first and deploy it. Later I create another project B and deploy it. If both projects use the default, they still work but it will be difficult to know which users come from each project.

For me, it is better if the default is set to the project name.

Edit 2:

I am talking about the applicationName attribute generated by Visual Studio in Web.config.
Why don't use the project name instead of / by default ?

<membership>
      <providers>
        <clear />
        <add name="AspNetSqlMembershipProvider"
             type="System.Web.Security.SqlMembershipProvider"
             connectionStringName="ApplicationServices"
             enablePasswordRetrieval="false"
             enablePasswordReset="true"
             requiresQuestionAndAnswer="false"
             requiresUniqueEmail="false"
             maxInvalidPasswordAttempts="5"
             minRequiredPasswordLength="6"
             minRequiredNonalphanumericCharacters="0"
             passwordAttemptWindow="10"
             applicationName="/" />
      </providers>
    </membership>
    <profile>
      <providers>
        <clear />
        <add name="AspNetSqlProfileProvider"
             type="System.Web.Profile.SqlProfileProvider"
             connectionStringName="ApplicationServices"
             applicationName="/" />
      </providers>
    </profile>
    <roleManager enabled="false">
      <providers>
        <clear />
        <add name="AspNetSqlRoleProvider"
             type="System.Web.Security.SqlRoleProvider"
             connectionStringName="ApplicationServices"
             applicationName="/" />
        <add name="AspNetWindowsTokenRoleProvider"
             type="System.Web.Security.WindowsTokenRoleProvider"
             applicationName="/" />
      </providers>

</roleManager>

EDIT 3:

After creating two applications (i.e., one as the root and the other one as the child app) and both have the same applicationName set to /, both application use the same ApplicationID. It means the slash has nothing to do with site domain tree. My confusion has been answered. So... why did Visual Studio set it to / (that makes confusion for me) by default?

EDIT 4:

I have two applications. One as the root application and the other one as the sub application under the former. Both use applicationName = "/". I got the result as follow in database: So what is the meaning of /? If no meaning, why did VS choose this confusing name rather than the project name?

alt text

EDIT 5:

From this article, I will make the summary:

  1. If we remove applicationName attribute from web.config for both applications, the ApplicationName generated in database for the root will be "/" and the ApplicationName generated in database for the sub app will be "/subappvirtualdir".
  2. If we leave the applicationName to its default value of "/" for both applications, both root app and sub app will get the same ApplicatonName of "/" generated in database.
  3. If we change the applicationName to "any name you want" for both applications, the ApplicationName generated in database will be set to "any name you want" for both applications.

Thanks Rockin for the link above !

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

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

发布评论

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

评论(2

谁的年少不轻狂 2024-10-15 13:50:19

我想说默认名称是 / 因为您的数据库不应该知道有关您的应用程序的任何信息。因此它不知道项目名称。他们必须有某种起点,并且由于他们不是读心者,因此您会得到一个 /

请记住,因为您可以使用 Aspnet_regsql.exe 要在完全独立于 Visual Studio 的数据库中创建 ASP.NET 成员资格方案,数据库不能仅自行“修复”应用程序名称。当然,您可以在创建数据库后立即在数据库中编辑应用程序名称,然后就不再重要了。

编辑

我在您的编辑中看到您正在谈论 web.config 中的 applicationName,而不是数据库中的 applicationName。请阅读这篇博客文章(不是我的)以获取更多见解
http://dotnettipoftheday.org/tips/applicationName_attribute.aspx

I'd say that the default name is / because your DB is not supposed to know anything about your app. Therefore it doesn't know the project name. They have to have some sort of starting point, and since they're not mind readers, you get a /.

Remember, since you can use Aspnet_regsql.exe to create your ASP.NET Membership Scheme in your database completely independent from Visual Studio, the database can't just "fix" the application name all on it's own. You can of course edit the app name in the database immediately after creating the db, then it doesn't matter anymore.

EDIT

I see in your edit that you're talking about the applicationName in the web.config, and not the one in the database. Please read this blog article (not mine) for some more insights
http://dotnettipoftheday.org/tips/applicationName_attribute.aspx

好菇凉咱不稀罕他 2024-10-15 13:50:19

应用程序通常不知道或关心它来自哪个“项目”。因此该上下文可能不会出现。

如果您的应用程序不在根目录下,请重命名它......

An application does not generally know or care what 'project' it came from. So that context likely would not be present.

And if your app isn't at the root, then rename it...

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