如何通过 ASP.NET 会员资格启用对所有站点的访问
Entity Framework code First
中实现 Membership Provider 的示例
我从 Imar Spaanjaars 的博客 /使用实体框架代码优先和 aspnet 成员资格一起” rel="nofollow">http://imar.spaanjaars.com/563/using-entity-framework-code-first-and-aspnet-membership-together
但目前我无法打开任何网站直到我注册或登录。
我怎样才能像模板 MVC 3
一样访问所有网站?
这是他的示例中的 web.config:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.web>
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
<!--
Enabling request validation in view pages would cause validation to occur
after the input has already been processed by the controller. By default
MVC performs request validation before a controller processes the input.
To change this behavior apply the ValidateInputAttribute to a
controller or action.
-->
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</configuration>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该示例有两个强制身份验证的内容:
Global.asax.cs
中的默认控制器/操作是Home/Index
。如果您未在请求中指定控制器/操作,则它将默认为Home/Index
。现在检查HomeController.cs::Index
HomeController.Index
具有需要经过身份验证的会话的[Authorize]
属性(即其中HttpContext .User.Identity.IsAuthenticated == true
)。唯一允许未经身份验证的请求的控制器/操作是 Account/* 和
Home/About
。从
HomeController::Index
中删除[Authorize]
属性,您无需身份验证即可访问它。That example has two things that force authentication:
Global.asax.cs
isHome/Index
. If you don't specify a controller/action in your request then it will default toHome/Index
. Now check outHomeController.cs::Index
HomeController.Index
has the[Authorize]
attribute which requires authenticated sessions (i.e. whereHttpContext.User.Identity.IsAuthenticated == true
).The only controllers/actions that allow for un-authenticated requests are Account/* and
Home/About
.Remove the
[Authorize]
attribute fromHomeController::Index
and you'll get to it without requiring authentication.