mvc中使用membership 权限 ( 安装和配置步骤)
2015-08-21 11:43
513 查看
第一步首先要安装membership对应数据库中的表
点击安装根据提示向下安装, 最后链接sql 选择自己对应的数据。
配置web.config文件
点击安装根据提示向下安装, 最后链接sql 选择自己对应的数据。
配置web.config文件
<?xml version="1.0" encoding="utf-8"?> <!-- For more information on how to configure your ASP.NET application, please visit http://go.microsoft.com/fwlink/?LinkId=169433 --> <configuration> <connectionStrings> <add name="ProjectDBContext" connectionString="Data Source=.;Initial Catalog=siaml;User ID=sa;password=123456;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" /> </connectionStrings> <appSettings> <add key="webpages:Version" value="2.0.0.0" /> <add key="webpages:Enabled" value="false" /> <add key="PreserveLoginUrl" value="true" /> <add key="ClientValidationEnabled" value="true" /> <add key="UnobtrusiveJavaScriptEnabled" value="true" /> <add key="Web.DefaultCulture" value="zh-CN" /> <!-- memorycache or netcache --> <add key="Web.CacheName" value="" /> <!-- rabbit or msmq --> <add key="Web.MqName" value="" /> </appSettings> <system.web> <compilation debug="true" targetFramework="4.0" /> //登陆权限 使用区域管理后台的权限 <authentication mode="Forms"> <forms name="Login" timeout="60" loginUrl="Admin/Users/Login" slidingExpiration="true" cookieless="AutoDetect" protection="All" requireSSL="false" enableCrossAppRedirects="false" defaultUrl="Admin/Home/Index" path="/"/> </authentication> <membership defaultProvider="ProjectProvider" userIsOnlineTimeWindow="5"> <providers> <clear/> <add name="ProjectProvider" connectionStringName="ProjectDBContext" //数据库名称 applicationName="Project" //解决方案名称 enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Hashed" minRequiredPasswordLength="3" minRequiredNonalphanumericCharacters="0" type="System.Web.Security.SqlMembershipProvider"/> </providers> </membership> //允许访问除去配置以外的文件 <authorization> <allow users="*"/> </authorization> //角色权限 applicationName //程序集名称 <roleManager enabled="true" defaultProvider="ProjectProvider"> <providers> <clear/> <add name="ProjectProvider" connectionStringName="ProjectDBContext" applicationName="Project" type="System.Web.Security.SqlRoleProvider"/> </providers> </roleManager> <!-- //表示任何用户都要验证 --> <!--<authorization> <allow users="*"/> </authorization>--> <pages> <namespaces> <add namespace="System.Web.Helpers" /> <add namespace="System.Web.Mvc" /> <add namespace="System.Web.Mvc.Ajax" /> <add namespace="System.Web.Mvc.Html" /> <add namespace="System.Web.Routing" /> <add namespace="System.Web.WebPages" /> </namespaces> </pages> </system.web> <system.webServer> <validation validateIntegratedModeConfiguration="false" /> <modules runAllManagedModulesForAllRequests="true" /> <handlers> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" /> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" /> <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" /> <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" /> <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> </handlers> </system.webServer> //添加方法让用户能页面和方法 不进行merbership的验证 <location path="home/adduserall"> <system.web> <authorization> <allow users="*"/> </authorization> </system.web> </location> </configuration>
相关文章推荐
- 软件工程文档中的数据库模型设计
- 【转】linux 定时执行shell脚本
- js中自定义事件,使用了jQuery
- 关于android.view.WindowLeaked异常的解决方案
- Android中Parcelable接口用法
- 九度oj 1110
- 【软工视频总结】需求分析
- svn 拉取分支
- CSS 简单样式
- Struts2验证框架的配置及validation.xml常用的验证规则
- [CareerCup] 5.7 Find Missing Integer 查找丢失的数
- 利用ant进行编译和发布项目
- 电商架构设计初步(待完善!!!)
- 那片野草
- sphinx全文搜索Php方面的简单处理
- Android:sqlite3:not found
- mongodb停止数据库
- Objective-C 【self的用法】
- = {0};VS的操作方式
- polay定理总结